Javascript Loop Control

The break and continue statements can be used to more precisely control the execution of a loop. The JavaScript Break statement, which was briefly introduced with the switch statement, is used to exit a loop early, breaking out of the enclosing curly braces.

Example of JavaScript Break

<!DOCTYPE html>
<html>
<head>
<title>we used JavaScript Break</title>
<script>
var a=1;
var b=5
while(a<8)
{
document.write(a+”<br>”);
if (a==6){
document.write(” Value of a is 6 and break “);
break;
}
a++;
}
</script>
<body>
</body>
</html>

Result of Javascript Loop Control :-

1

2

3

4

5

6

Value of a is 6 and break




Follow Us

Contact Us

tutorialworldin@yahoo.com

Back to Top