break statement syntax : Break « Statement « JavaScript Tutorial

Home
JavaScript Tutorial
1.Language Basics
2.Operators
3.Statement
4.Development
5.Number Data Type
6.String
7.Function
8.Global
9.Math
10.Form
11.Array
12.Date
13.Dialogs
14.Document
15.Event
16.Location
17.Navigator
18.Screen
19.Window
20.History
21.HTML Tags
22.Style
23.DOM Node
24.Drag Drop
25.Object Oriented
26.Regular Expressions
27.XML
28.GUI Components
29.Dojo toolkit
30.jQuery
31.Animation
32.MS JScript
JavaScript Tutorial » Statement » Break 
3.9.1.break statement syntax

The keyword break exits out of loop structures and switch statement.

When a label is used, JavaScript completely breaks out of the area designated by label.

To label a statement, place the label name followed by a colon (:).

Labels are useful when working with nested loops.

<html>
    <SCRIPT LANGUAGE='JavaScript'>
    <!--
    forLoop1:
    for (var counter1 = 1; counter1 <= 5; counter1++)
    {
      for (var counter2 = 1; counter2 <= 5; counter2++)
      {
        document.write("Counter1=",counter1);
        document.write(" Counter2=",counter2,"<BR>");
        if (counter2 == 3)
          break;
        if (counter1 == 3)
          break forLoop1;
      }
    }
    document.write("All done!");
    //-->
    </SCRIPT>
</html>
3.9.Break
3.9.1.break statement syntax
3.9.2.Break a while statement
3.9.3.Break statement in a if statement
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.