`loop` and `recur` provide controlled repetition without a mutable loop counter. `loop` establishes local bindings; `recur` supplies their next values and restarts the innermost enclosing `loop` or function. When execution leaves the loop, its last expression supplies the result. section 3.4 section 3.4.1
Collect ten squares
```clojure (loop [i 0 s []] (if (< i 10) (recur (inc i) (conj s (* i i))) s)) ;; [0 1 4 9 16 25 36 49 64 81] ``` Each `recur` supplies a replacement for both bindings. Once `i` reaches 10, the loop returns the accumulated vector. section 3.4
Choose the recursion target deliberately:
- Inside a function, `recur` targets the innermost enclosing function if there is no nearer `loop`. A `loop` can instead initialize working values without adding function arguments. section 3.4.1
- `recur` must be in tail position; the compiler rejects it elsewhere. Unlike an ordinary recursive call, it uses an optimization that does not consume stack space for each repetition. section 3.4.1
Keep working values local
```clojure (defn fib [n] (loop [a 1 b 0 cnt n] (if (zero? cnt) b (recur (+ a b) a (dec cnt))))) (map fib (range 10)) ;; (0 1 1 2 3 5 8 13 21 34) ``` The function accepts only `n`; the loop owns the additional values needed for iteration. For collection-wide tests, prefer an operation such as `every?` when it already expresses the job: its general implementation uses tail-recursive `recur`. section 3.4.1 section 8.1.5
