|
| JAVASCRIPT BREAK STATEMENT
In javascript programming, the break word is used to terminate the further execution of a loop if a certain test condition is met.
The break word is situated in the loop after a condition. As soon the test condition is met, the loop stops immediately.
Example Without Break:
i=1;
while(i < 10)
{
document.write("Hello<br>");
i++;
}
The above will output Hello nine times and the loop ends naturally.
Example With Break:
i=1;
while(i < 10)
{
document.write("Hello<br>");
if(i== 4)
break;
i++;
}
The above will output Hello four times and the loop ends prematurely when the test condition of i==4 is met.
|
|