do-while Loop

After for loop and while loop in JavaScript , another most common loop used is do-while loop in JavaScript. The do-while loop in JavaScript is a control flow statement that allows you to execute a block of code repeatedly as long as a specified condition becomes true. Unlike other loops, the do-while loop guarantees the execution of a block of code at least once before checking the condition. It prints the statement at least once and then checks the condition.

The syntax of do-while loop in JavaScript is:

do{
    //code
} while(condition);

Here's how the do-while loop works:

  1. The code block inside the do statement is executed first, without checking any conditions.
  2. After executing the code block, the condition in the while statement is evaluated.
  3. If the condition evaluates to true, the code block is executed again. The loop continues until the condition becomes false.
  4. If the condition initially evaluates to false, the code block is still executed once before exiting the loop.
500 Internal Server Error

500 Internal Server Error