控制流 / 控制流中断

(require '[clojure.string :as str])

(def numbers [2 3 5 7 11 13 17 19])

;; Clojure has no "continue" either: skipping an item is either
;; a guard around the body or a filter applied before the loop
(def s (str/join "-" (keep-indexed (fn [i n] (when (even? i) n)) numbers)))
;; s is "2-5-11-17"
(println "s is" s)

;; in a loop the skip is a branch that recurs without doing the work
(println "in a loop:"
         (str/join "-"
                   (loop [i 0, acc []]
                     (cond
                       (= i (count numbers)) acc
                       (odd? i) (recur (inc i) acc) ; <- this is "continue"
                       :else (recur (inc i) (conj acc (numbers i)))))))