get it on google playCreated with Sketch.
JavaScript> While Loops

While Loops

To control the times a while loop repeats, we start with a variable set to a number. We call this variable a counter variable.

var counter = 1;

Then, we use a comparison in the condition to compare the counter variable to a number. In this case, counter < 4.

var counter = 1;

while (counter < 4) {
 
}

Inside the code block, we make the condition return false and stop the loop by incrementing the counter variable. Try it with counter++.

var counter = 1;

while (counter < 4) {
 console.log(counter);
 counter++;
}
TRY IT ON THE APP