Skip to content

Commit 0b5fe1a

Browse files
committed
Clarified what is going on inside a for-loop
Response to workshopper#54
1 parent ba5641c commit 0b5fe1a

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

problems/for-loop/problem.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
For loops look like this:
1+
For loops allow you to repeatedly run a block of code a certain number of times. This for loop logs to the console ten times:
22

33
```js
44
for (var i = 0; i < 10; i++) {
@@ -7,12 +7,11 @@ for (var i = 0; i < 10; i++) {
77
}
88
```
99

10-
The variable `i` is used to track how many times the loop has run.
10+
The first part, `var i = 0`, is run once at the beginning of the loop. The variable `i` is used to track how many times the loop has run.
1111

12-
The statement `i < 10;` indicates the limit of the loop.
13-
It will continue to loop if `i` is less than `10`.
12+
The second part, `i < 10`, is checked at the beginning of every loop iteration before running the code inside the loop. If the statement is true, the code inside the loop is executed. If it is false, then the loop is complete. The statement `i < 10;` indicates that the loop will continue as long as `i` is less than `10`.
1413

15-
The statement `i++` increases the variable `i` by 1 each loop.
14+
The final part, `i++`, is executed at the end of every loop. This increases the variable `i` by 1 after each loop. Once `i` reaches `10`, the loop will exit.
1615

1716
## The challenge:
1817

0 commit comments

Comments
 (0)