Javascript Loop Control

In Javascript, when required you can stop or come out from the loop by placing break statement in the Javascript Loop Control.

The Break Statement

The break statement is used to come out or stop the loop.


<script type="text/javascript">
for(int i=0;i<=10;i++){

Note: The <= could be anything that would fit the purpose ex. >, == or whatever.

Javascript Do While Loop Example

<!DOCTYPE html>
<head>  <!-- -->
<title>My first Javascript code</title>   
<body bgcolor="#bnde45">
<legend>Javascript Do While Loop</legend>
<script type="text/javascript">
for (j=0; j<=10; j++)
	if(j > 5){
		document.write("<b>The number is " + j + "</b>")
<p>The for loop sets <b>i<b> equal to 0.
<p>As long as <b>i</b> is less than or equal to 10, 
the loop will continue to run.
<p><b>i</b> will increase by 1 each time the loop runs.