Skip to content

Commit da283d9

Browse files
arthurvrKrinkle
authored andcommitted
javascript-101/loops: add for...in loop
Closes gh-588 Fixes gh-321
1 parent 6104267 commit da283d9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

page/javascript-101/loops.md

+12
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ for (var i = 0, limit = 100; i < limit; i++) {
4646
}
4747
```
4848

49+
## The `for...in` loop
50+
51+
+A `for...in` loop iterates over the properties of an object. For each property, statements can be executed.
52+
+
53+
+```
54+
+for ( prop in obj ) {
55+
// statements here will be executed for every key in the object
56+
console.log( prop + ': ' + obj[ prop ] );
57+
}
58+
``
59+
60+
4961
## The `while` loop
5062

5163
A while loop is similar to an `if` statement, except that its body will keep executing until the condition evaluates to a falsy value.

0 commit comments

Comments
 (0)