JavaScript Continue Instructions
There are things which should be noticed also, there are times we need to jump on one or more specific values in the loop without stopping the loop itself.
The syntax used here is to continue, and it’s placed in the loop itself, in general we also add conditional structure as a condition so that the syntax is going well.
There are things which should be noticed also, there are times we need to jump on one or more specific values in the loop without stopping the loop itself.
The syntax used here is to continue, and it’s placed in the loop itself, in general we also add conditional structure as a condition so that the syntax is going well.
Example: we will print the results of equation 1 / (x-7) to the value of x = 1 to x = 10, we know that if the value of x = 7 it will produce an error (division by 0), by continue instructions
we can treat separately the value of x = 7, and continue the loop of the program.
x = 1;
while (x <= 10) {
if (x == 7) {
Alert ('division by 0 ');
x + +;
continue;
}
a = 1 / (x-7);
Alert (a);
x + +;
}
0 comments:
Post a Comment