Files

46 lines
606 B
Markdown
Raw Normal View History

2018-10-12 15:37:13 -04:00
---
title: Iterate with JavaScript While Loops
---
# Iterate with JavaScript While Loops
---
## Problem Explanation
2018-10-12 15:37:13 -04:00
While loops will run as long as the condition inside the ( ) is true.
2018-10-12 15:37:13 -04:00
Example:
2018-10-12 15:37:13 -04:00
```javascript
while (condition) {
//code...
2018-10-12 15:37:13 -04:00
}
```
---
## Hints
### Hint 1
2018-10-12 15:37:13 -04:00
Use a iterator variable such as i in your condition
```javascript
var i = 0;
while (i <= 4) {}
2018-10-12 15:37:13 -04:00
```
---
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
2018-10-12 15:37:13 -04:00
```javascript
// Setup
var myArray = [];
// Only change code below this line.
var i = 0;
while (i <= 4) {
myArray.push(i);
i++;
2018-10-12 15:37:13 -04:00
}
```
</details>