Skip to content

Commit 82e9913

Browse files
committed
Add Dofor section
1 parent f6335da commit 82e9913

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

content/documentation/control-flow.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Internally `recur` is implemented as a PHP while loop and therefore prevents the
9595
(foreach [value valueExpr] expr*)
9696
(foreach [key value valueExpr] expr*)
9797
```
98-
The `foreach` special form can be used to iterate over all kind of PHP datastructures. The return value of `foreach` is always `nil`. The `loop` special form should be preferred of the `foreach` special form whenever possible.
98+
The `foreach` special form can be used to iterate over all kind of PHP datastructures for side-effects. The return value of `foreach` is always `nil`. The `loop` special form should be preferred of the `foreach` special form whenever possible.
9999

100100
```phel
101101
(foreach [v [1 2 3]]
@@ -155,6 +155,15 @@ have the form `:modifier argument`. The following modifiers are supported:
155155
(for [x :range [0 4] y :range [0 x]] [x y]) # Evaluates to [[1 0] [2 0] [2 1] [3 0] [3 1] [3 2]]
156156
```
157157

158+
# Dofor
159+
160+
```
161+
(dofor [x :in [1 2 3]] (print x)) # Prints 1, 2, 3 and returns nil
162+
(dofor [x :in [2 3 4 5] :when (even? x)] (print x)) # Prints 1, 2 and returns nil
163+
```
164+
165+
Iterating over collections for side-effects is also possible with `dofor` which has similar behavior to `for` otherwise but returns `nil` as `foreach` does.
166+
158167
## Exceptions
159168

160169
```phel

0 commit comments

Comments
 (0)