Glossary
HTML
CSS
JavaScript
Python

JAVASCRIPT

While Loops in JAVASCRIPT

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

JavaScript

let counter = 1;

 

 

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

JavaScript

let 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++.

JavaScript

let counter = 1;
while (counter < 4) {
 console.log(counter);
 counter++;
}
Learn to Code in Python for Free
Start learning now
To advance beyond this tutorial and learn Python by doing, try the interactive experience of Mimo. Whether you're starting from scratch or brushing up your coding skills, Mimo helps you take your coding journey above and beyond.

Sign up or download Mimo from the App Store or Google Play to enhance your programming skills and prepare for a career in tech.

You can code, too.

© 2023 Mimo GmbH