Break and continue part 2

JavaScript Tutorial
Conditionals and Loops
Break and Continue
31
2/2
         

Continue



The continue statement breaks only one iteration in the loop, and continues with the next iteration.
for (i = 0; i <= 10; i++) {
if (i == 5) {
continue;
}
document.write(i + "<br />");
}
Try It Yourself

Result:
The value 5 is not printed, because continue skips that iteration of the loop.
What is the output of this code?
var sum=0;
for(i=4; i<8; i++) {
if (i == 6) {
continue;
}
sum += i;
}
document.write(sum);
 
 16

Comments

Popular posts from this blog

Comparison Operators part 2

Break and Continue part 1

Module 2