Page 107 - PortGPT_V2.1_C8_Flipbook
P. 107
<H3> Using break Statement </H3>
<SCRIPT>
var i = 0;
while (i <= 5)
{
document.write("Value of i is: " + i +"<BR>");
if(i == 3)
{
document.write("loop break");
break;
}
i++;
}
</SCRIPT>
</BODY>
</HTML>
In the preceding code, you can see when the value of the variable i becomes 3, the break statement
is executed and loop will break. The output of the Program 4 is:
The Continue Statement
A continue statement stops the execution of the current iteration of the loop and sends the control
of the program to the beginning of the loop for next iteration. It skips the execution of rest of the
statements of the loop for the current iteration. The syntax of the continue statement is same as the
break statement. Let us create a web page to use the continue statement.
Program 6: To display numbers from 1 to 10 except number 6 by using the continue statement.
<HTML>
<HEAD>
<TITLE> Using continue Statement </TITLE>
</HEAD>
Loops in JavaScript 105

