{:check ["true"]}
Recall the for
iteration over sequences.
(for [binding...]
expr)
The for
form evaluates to the resulting sequence.
Sometimes, we just want to perform some side-effects during the iteration, and not accumulate any resulting sequence.
;
; Print the solutions of x^2 + 4y = x * y
; for x in 0 .. 100 and y in 0 .. 100
;
(for [x (range 100)
y (range 100)
:when (= (+ (* x x) (* 4 y)) (* x y))]
(println "x" x "y" y))
Clojure provides a near-identical form:
(doseq [binding*]
expr*)
;
; Print the solutions of x^2 + 4y = x * y
; for x in 0 .. 100 and y in 0 .. 100
;
(doseq [x (range 100)
y (range 100)
:when (= (+ (* x x) (* 4 y)) (* x y))]
(println "x" x "\ty" y))
(dotimes [<symbol> <number>]
expr*)
(dotimes [n 10]
(println "Hello world" n))