while(x < 10) {
console.log(x);
x++;
}
The general rule for deciding between using a for loop and a while loop is as follows.
If you know the exact number of iterations you want your loop to run for, then use a for loop; if you have a rough idea about how many times you want the loop to run, but don’t know the exact number, then a while loop is better suited.
The do/while loop is a variation on the while loop, in which we are able to write a loop that is guaranteed to always run at least once. Looking at the syntax we can see why this is the case: