Break Statement
Example
<script type="text/javascript">
var i=0
for(i=0;i<=10;i++)
{
if (i==5)
{
break;
}
document.write("The number i = " +i);
document.write("<br />");
}
</script>
var i=0
for(i=0;i<=10;i++)
{
if (i==5)
{
break;
}
document.write("The number i = " +i);
document.write("<br />");
}
</script>
Output
The number i = 0The number i = 1
The number i = 2
The number i = 3
The number i = 4
Note: From output that when i = 5, the execution is terminated from loop.
No comments:
Post a Comment