Thursday, May 21, 2009

JavaScript Break and Continue Statements.


The break Statement.


The break statement will break the loop and continue executing the code that follows after the loop (if any).

Example.


<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=10;i++)
{
if (i==3)
{
break;
}
document.write("The number is " + i);
document.write("<br />");
}
</script>
</body>
</html>

The continue Statement.


The continue statement will break the current loop and continue with the next value.

Examplet.


<html>
<body>
<script type="text/javascript">
var i=0
for (i=0;i<=10;i++)
{
if (i==3)
{
continue;
}
document.write("The number is " + i);
document.write("<br />");
}
</script>
</body>
</html>

No response to “JavaScript Break and Continue Statements.”

Post a Comment