for and doseq with conditions

less than 1 minute read

Code

;; for_doseq_with_conditions.clj

(for [x [:a :b], y (range 5) :when (odd? y)]
  [x y])

(doseq [x [:a :b], y (range 5) :when (odd? y)]
  (prn x y))

(for [x (range 10) :when (even? x), y (range 5) :when (odd? y)]
  [x y])

(for [x (range 10) :when (odd? x), y (range 5) :when (odd? y)]
  [x y])

;; didn't work 
;; (for [x (range 10) :when (odd? y), y (range 5) :when (odd? y)]
;;   [x y])

;; weird
(for [x (range 10), y (range 5) :when (odd? x)]
  [x y])

(for [x (range 10), y (range 5) :when (and (odd? x) (even? y))]
  [x y])

Updated: