Javascript language

adplus-dvertising
JavaScript Continue and Break Statements
Previous Home Next

The continue Statement

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

Example

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

Run the Code

The break Statement

The break statement will break the loop and continue executing the code that follows after the loop.

Example

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

Execute the Code

Previous Home Next