Skip to content

Commit 71bb1c4

Browse files
authored
Merge pull request #176 from Flipez/loop-return
[foreach/while] Document return value
2 parents fb87f9e + 92c46dd commit 71bb1c4

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

docs/docs/control_expressions/foreach.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ end
2424
input = a
2525
```
2626

27+
## Return Value
28+
Loops do return the variable they are iterating after the last loop.
29+
30+
```js
31+
def iterate(items)
32+
foreach item in items
33+
puts(item)
34+
end
35+
end
36+
37+
a = [1,2,3,4,5]
38+
39+
b = iterate(a)
40+
41+
// b is now [1,2,3,4,5]
42+
```
43+
2744
## Using an integer
2845
Count form zero to a given number (excluding):
2946

docs/docs/control_expressions/while.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,21 @@ end
4545
4
4646
5
4747
6
48+
```
49+
50+
## Return Value
51+
Loops do return the variable they are iterating after the last loop.
52+
53+
```js
54+
def iterate(items)
55+
foreach item in items
56+
puts(item)
57+
end
58+
end
59+
60+
a = [1,2,3,4,5]
61+
62+
b = iterate(a)
63+
64+
// b is now [1,2,3,4,5]
4865
```

0 commit comments

Comments
 (0)