JS while and do while

while Loop:

The while loop executes as long as the specified condition evaluates to true. The condition is evaluated before the code block executes.


Syntax:

while (condition) { 
  // Code to execute 
}
Example
let count = 0;

while (count < 5) {
console.log(count);
count++;
}

Try it yourself


do...while Loop:

The do...while loop executes the code block at least once, regardless of the condition. The condition is evaluated after the code block executes.


Syntax:

do {
    // Code to execute
} while (condition);
Example
let count = 0;

do {
console.log(count);
count++;
} while (count < 5);

Try it yourself


Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.