Difference between "do" and "for" looping [Answered]

Hi. Here’s a simple question:
So, in “for” loop, you use parentheses,
but to do a “do” you have to use a curly brackets?
Thank you.

1 Like

The syntax of do..while is such that values don’t need to be defined on entry, and the loop has no entry condition so will execute its code block at least once.

let a;
do {
    a = Math.floor(Math.random() * 10 + 1)
} while (a !== 5)

The loop will continue until the number 5 is generated. Not the most practical example, but it demonstrates the nature. Note that the block comes before the condition.

5 Likes

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