advanced
 
 

SocialTwist Tell-a-Friend

Introduction Syntax Placement Variables Operators Popup Boxes If Else Statement Switch Case while Loop for Loop break continue Function Array DOM Events Date String Form Validation

JavaScript : The break Statement

The break statement is used to break the loop and continue executing the code that follows after the loop (if any).

      <html>
      <body>
      <script type="text/javascript">
      var i=0;
      for (i=0;i<=5;i++)
		{
		  if (i==3)
		      {
		      break;
		      }
		      document.write("Number " + i);
		      document.write("<br />");  
		}
		</script>
		</body>
		</html>
      

The output will be

 Number 0
 Number 1
 Number 2
 
The loop will break when i=3.
Previous            Next
Contact Us
Your Ad Here