Loop control in JavaScript
JavaScript provides high control to handle loop commands and switch commands. There may be a situation when you need to exit the loop without having to go to its endpoint. There may also be situations when you want to jump over a part of the code block and start the next loop.
JavaScript provides high control to handle loop commands and switch commands. There may be a situation when you need to exit the loop without having to go to its endpoint. There may also be situations when you want to jump over a part of the code block and start the next loop.
To handle the above situations, JavaScript provides break and continue commands. These commands are used to immediately exit any loop or to start the next loop of any corresponding loop.
Break command
The break command, introduced briefly with the switch command, is used to exit soon from a loop, leaving the brace area.
Implementation diagram
Implementation diagram of a break statement is as follows:
For example
The following example illustrates the use of the break statement with a while loop . Notice how the loop exits early when x proceeds to 5 and goes to the document.write command (.) right below the closed parenthesis.
- How to Print Double Quotes in Java
- How to Create an Executable File from Eclipse
- How to Enable Webgl
- How to Create a Javascript Console in Sublime Text
- How to Close a Window in Java
- How to Print an Array in Java
- Introduction to 2D Array - 2-dimensional array in JavaScript
- How to Run Program C/C++ Program in Netbeans
- How to Enable JavaScript in Mozilla Firefox
- How to Check Null in Java