Browse Learn Clojure Foundations as a Java Developer

The loop Construct in Clojure

Write explicit local loops with loop/recur when an algorithm needs evolving bindings, early termination, or state transitions that are clearer than a pipeline or reduce.

loop introduces a set of local bindings and a recursion point that recur can jump back to. Together, loop/recur is the idiomatic way to write an explicit loop without mutating variables.

You use it when:

  • you need multiple evolving values (like two indexes, or a queue + accumulator)
  • early termination matters
  • the loop logic is clearer than a deeply nested reduce

Java mental model: this is the “while loop” tool, but the evolving state is explicit in the binding vector instead of being mutated in place.

This section helps you recognize when loop/recur is the simplest option and how to keep it readable.

In this section

  • Using loop and recur in Clojure
    Use loop to create a local recursion point and recur to update bindings without mutable Java-style loop variables or unbounded stack growth.
  • loop/recur Examples in Clojure
    Practice loop/recur with counters, accumulators, collection scans, and state transitions so Java loop patterns translate into clear Clojure code.
Revised on Saturday, May 23, 2026