JavaScript Loop - Break a loop

Submitted by:Jhon Jhon

Date added:08 March, 2012

Category:JavaScript

A javaScript loop example with Break a loop

Tags: break a loop

Code Snippet:

<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=10;i++)
{
if (i==3)
{
break;
}
document.write("The number is " + i);
document.write("<br />");
}
</script>
<p>Explanation: The loop will break when i=3.</p>
</body>
</html>

 
 

Comments