JavaScript Break Instruction


JavaScript Break Instruction

We can force the loop stops before it’s time for reasons that definite at the beginning of the loop. Break instruction allows to stop a loop (either for the for or while loop). How to use is such as continue instructions, namely the addition of conditional structure in order to stop the loop.

Example:

for (x = 1; x <= 10; x + +) {
a = x-7;
if (a == 0) {
Alert ('division by 0 ');
break;
}
Alert (1 / a);
}

0 comments:

Post a Comment