HOLLA TECH - LEARN

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 />”);

 

Once i reaches 5, it will break out of the loop.

Holla Tech - Learn JavaScript

NOTE!
You can use the return keyword to return some value immediately from the loop inside of a function. This will also break the loop.

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 />”);

 

Result: 

Holla Tech - Learn JavaScript

NOTE!
The value 5 is not printed, because continue skips that iteration of the loop.

BACK NEXT

CLICK ON THE BUTTON BELOW TO GO TO THE JAVASCRIPT MAIN COURSE PAGE. 

JAVASCRIPT MAIN COURSE PAGE

 


© License: All Rights Reserved 


CONTACT HOLLA TECH – LEARN SUPPORT