Break and Continue part 1

Break



The break statement "jumps out" of a loop and continues executing the code after the loop.
for (i = 0; i <= 10; i++) {
if (i == 5) {
break;
}
document.write(i + "<br />");
}
Try It Yourself

Once i reaches 5, it will break out of the loop.
You can use the return keyword to return some value immediately from the loop inside of a function. This will also break the loop.
The "break" statement:

Stops the whole script
Ends the execution of the loop
Ignores the current iteration and passes to the next

Comments

Popular posts from this blog

Introducing object part 3

Comparison Operators part 2

Module 2