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.


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.


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