You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/documentation/control-flow.md
+10-1Lines changed: 10 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,7 +95,7 @@ Internally `recur` is implemented as a PHP while loop and therefore prevents the
95
95
(foreach [value valueExpr] expr*)
96
96
(foreach [key value valueExpr] expr*)
97
97
```
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.
99
99
100
100
```phel
101
101
(foreach [v [1 2 3]]
@@ -155,6 +155,15 @@ have the form `:modifier argument`. The following modifiers are supported:
(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.
0 commit comments