Skip to content

Commit 31329ed

Browse files
committed
Add introduction for loops
1 parent 6d77126 commit 31329ed

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

SUMMARY.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@
1616
* [If](conditional/if.md)
1717
* [Else](conditional/else.md)
1818
* [Comparators](conditional/comparators.md)
19-
* [Concatenate](conditional/concatenate.md)
19+
* [Concatenate](conditional/concatenate.md)
20+
* [Loops](loops/README.md)
21+
* [For](loops/for.md)
22+
* [While](loops/while.md)

loops/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Loops
2+
3+
Loops are repetitive conditions where one variable in the loop changes. Loops are handy, if you want to run the same code over and over again, each time with a different value.
4+
5+
Instead of writing:
6+
7+
```javascript
8+
doThing(cars[0]);
9+
doThing(cars[1]);
10+
doThing(cars[2]);
11+
doThing(cars[3]);
12+
doThing(cars[4]);
13+
```
14+
15+
You can write:
16+
17+
```javascript
18+
for (var i=0; i < cars.length; i++) {
19+
doThing(cars[i]);
20+
}
21+
```

0 commit comments

Comments
 (0)