--- id: cf1111c1c11feddfaeb1bdef title: Iterate with JavaScript While Loops challengeType: 1 --- ## Description
You can run the same code multiple times by using a loop. The first type of loop we will learn is called a "while" loop because it runs "while" a specified condition is true and stops once that condition is no longer true.
var ourArray = [];
var i = 0;
while(i < 5) {
  ourArray.push(i);
  i++;
}
Let's try getting a while loop to work by pushing values to an array.
## Instructions
Push the numbers 0 through 4 to myArray using a while loop.
## Tests
```yml tests: - text: You should be using a while loop for this. testString: assert(code.match(/while/g), 'You should be using a while loop for this.'); - text: myArray should equal [0,1,2,3,4]. testString: assert.deepEqual(myArray, [0,1,2,3,4], 'myArray should equal [0,1,2,3,4].'); ```
## Challenge Seed
```js // Setup var myArray = []; // Only change code below this line. ```
### After Test
```js if(typeof myArray !== "undefined"){(function(){return myArray;})();} ```
## Solution
```js var myArray = []; var i = 0; while(i < 5) { myArray.push(i); i++; } ```