HOLLA TECH - LEARN

The Do…While Loop
 

The do…while loop is a variant of the while loop. This loop will execute the code block once, before checking if the condition is true, and then it will repeat the loop as long as the condition is true.

Syntax: 

do {
   code block
}
while (condition); 

 

NOTE!
Note the semicolon used at the end of the do…while loop.

var i=20;
do { 
  document.write(i + “<br />”);
  i++; 
}
while (i<=25); 

 

This prints out numbers from 20 to 25.

Holla Tech - Learn JavaScript

NOTE!
The loop will always be executed at least once, even if the condition is false, because the code block is executed before the condition is tested.

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