var a = 0;
if (i==5 || i==10 || i==15 || i==20)
alert( i + " is a...MULTIPLE OF FIVE!");
document.write("The number is " + i);
break statement were substituted in the above code, the output would be:
This is number 1
Thus is number 2
This is number 3
This is number 4
5 is a…MULTIPLE OF FIVE! //alert box
and then terminate
From slashdot, ErichTheRed writes:
So What Exactly Does Break and Continue “Do”?
So just to clarify, what does the continue statement actually “do”? Well, both
break say to the current conditional (if, if-else) or iterative (for, while, do-while) loop
“Don’t execute subsequent code in the function!”
break statements do that, but the difference is that
continue simple reevaluates the function again, in a sense merely “skipping” the subsequent statements after that one instance that brought
continue to be executed. The
break statement, on the other hand, says “Don’t execute subsequent code in the function!” and then breaks out of the rest of the loop, in a sense aborting the rest of the iterative or conditional loop.
Thus, I like to think of the break statement as an “abort!” and the continue as “hold up, I’ll take that or I’ll adjust that, now back to what you were doing!” effect. You can connote whatever you want with them, but continue and break are extremely potent statements to make your functions, loops, and conditionals behave in advanced ways, accomplishing what you want!
Some other resources (defining the exact same thing we have detailed above but just using slightly different wording, because people learn differently, the altered wording may help or hurt your comprehension).
From IBM’s site (just one of the many random resources detailing continue statements):
A continue statement ends the current iteration of a loop. Program control is passed from the continue statement to the end of the loop body.
A continue statement has the form:>>-continue--;-------------------------------------------------><
A continue statement can only appear within the body of an iterative statement.
The continue statement ends the processing of the action part of an iterative (do, for, or while) statement and moves control to the loop continuation portion of the statement. For example, if the iterative statement is a for statement, control moves to the third expression in the condition part of the statement, then to the second expression (the test) in the condition part of the statement.
Within nested statements, the continue statement ends only the current iteration of the do, for, or while statement immediately enclosing it.”
This is all basically what we just said. The continue statement’s “processing” and brings the focus back to the loop-control (in “for” this would be the increment, in a “while” this would be the conditional evaluation and the like!)