--- id: cf1111c1c11feddfaeb1bdef title: Iterate with JavaScript While Loops challengeType: 1 videoUrl: '' localeTitle: 在循环时使用JavaScript进行迭代 --- ## Description
您可以使用循环多次运行相同的代码。我们将学习的第一种类型的循环称为“ while ”循环,因为它在“while”运行时指定的条件为true,并且一旦该条件不再为真就停止。
var ourArray = [];
var i = 0;
而(i <5){
ourArray.push(ⅰ);
我++;
}
让我们尝试通过将值推送到数组来实现while循环。
## Instructions
使用while循环将数字0到4推送到myArray
## Tests
```yml tests: - text: 你应该使用while循环。 testString: 'assert(code.match(/while/g), "You should be using a while loop for this.");' - text: 'myArray应该等于[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 console.info('after the test'); ```
## Solution
```js // solution required ```