Monday 16 July 2012

How to create Break a loop using javascript


<!DOCTYPE html>
<html>
<body>

<p>Click the button to do a loop with a break.</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)
    {
    break;
    }
  x=x + "The number is " + i + "<br />";
  }
document.getElementById("demo").innerHTML=x;
}
</script>

</body>
</html>

0 Responses to “How to create Break a loop using javascript”

Post a Comment