Do...While Loops

Tell us what’s happening:
Describe your issue in detail here.
For some reason even though i isn’t less than 5 the while loop still executes. Why is this happening i don’t get it at all since as to my knowledge loops stop if the argument is false

  **Your code so far**

// Setup
const myArray = [];
let i = 10;

// Only change code below this line
do {
while (i < 5) {
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0

Challenge: Iterate with JavaScript Do…While Loops

Link to the challenge:

It is called a do…while loop because it will first do one pass of the code inside the loop no matter what, and then continue to run the loop while the specified condition evaluates to true.

The code always executes the body of the loop at least once.

1 Like

This is invalid.
In a do...while loop, there is no second loop body. There shouldn’t be any braces ({}) after the while condition.


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.