01 September 2013

Difference between the break and continue in programming language


BREAK
Break
 The break statement will terminate iteration of the loop and continue executing if there is any code that follows after the loop. Example of Break statement in JavaScript:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<script>

x=0;

for(x=0;x<10;x++)
{
if(x==3)
{
break;    
}
document.writeln("x=" + x + "<br />");

}


</script>
Output: x=0 x=1 x=2

Continue
Continue

The continue statement will terminate the current execution of loop and resume the loop with the next value if any. Example of Continue statement in JavaScript:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<script>

xx=0;

for(xx=0;xx<5;xx++)
{
if(xx==3) 
{
continue;
}
document.writeln("xx=" + xx + "<br />");
}

</script>
Output: xx=0 xx=1 xx=2 xx=4
Beginning Programming All-In-One Desk Reference For Dummies

No comments:

Post a Comment

Featured Post

How to Write PHP code and HTML code within a same file

A PHP file can have both PHP code and HTML code together. Any HTML code written outside of PHP <?php //php code here… ?> Code is ig...

Popular Posts