14 lines
549 B
Markdown
Raw Normal View History

2018-10-12 15:37:13 -04:00
---
title: Iterate with JavaScript While Loops
---
2019-01-17 12:02:35 -06:00
Another type of JavaScript loop is called a `while loop` because it runs `while` something is true, and stops once that something is no longer true. Unlike the `for loop`, which is made up of three parts, the `while loop` only contains a condition statement.
2018-10-12 15:37:13 -04:00
var ourArray = [];
var i = 0;
while(i < 5) {
ourArray.push(i);
i++;
2019-01-17 12:02:35 -06:00
}
It is important to remember to increase the variable used in this example, without the addition of `i++` the loop would continue forver.