Monday 16 July 2012

How to use Break and continue a loop in javascript


<!DOCTYPE html>
<html>
<body>

<p>Click the button to do a loop which will skip the step where i=3.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

<script type="text/javascript">
function myFunction()
{
var x="",i=0;
for (i=0;i<10;i++)
  {
  if (i==3)
    {
    continue;
    }
  x=x + "The number is " + i + "<br />";
  }
document.getElementById("demo").innerHTML=x;
}
</script>

</body>
</html>

0 Responses to “How to use Break and continue a loop in javascript”

Post a Comment