The Do...While Loop

JavaScript Tutorial
Conditionals and Loops
The Do...While Loop
16

1/1
   

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 the semicolon used at the end of the do...while loop.
Example:
var i=20;
do {
document.write(i + "<br />");
i++;
}
while (i<=25);
Try It Yourself

This prints out numbers from 20 to 25.
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 tes
Apply the "do" and "while" keywords in their corresponding positions.
var count=1;
 
 
 {
  document.write("hello <br />");
  count++;
}
 
 
 (count<=10);

Comments

Popular posts from this blog

Introducing object part 3

Comparison Operators part 2

Module 2