A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/javascript/statements/break below:

break · WebPlatform Docs

break Summary

Terminates the current loop or, if in conjunction with a label, terminates the associated statement.

Syntax
break [ label ];
Examples

In this example, the counter is set up to count from 1 to 99; however, the break statement terminates the loop after 14 counts.

for (var i = 1; i < 100; i++) {
     if (i == 15) {
         break;
     }
     document.write (i);
     document.write (" ");
 }

 

In the following code, the break statement refers to the for loop that is preceded by the Inner: statement. When j is equal to 24, the break statement causes the program flow to exit that loop. The numbers 21 through 23 print on each line.

Outer:
 for (var i = 1; i <= 10; i++) {
     document.write ("<br />");
     document.write ("i: " + i);
     document.write (" j: ");
 Inner:
     for (var j = 21; j <= 30; j++) {
         if (j == 24) {
             break Inner;
         }
         document.write (j + " ");
     }
 }

 
 
 
 
 
 
 
 
 
 
 
Remarks

The optional label argument specifies the label of the statement you are breaking from.

You typically use the break statement in switch statements and in while , for , for…in , or do…while loops. You most commonly use the label argument in switch statements, but it can be used in any statement, whether simple or compound.

Executing the break statement exits from the current loop or statement, and begins script execution with the statement immediately following.

See also Other articles Attributions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4