Browse Clojure Foundations for Java Developers

The loop Construct

Write explicit local loops with loop/recur when a pipeline or reduce is not the best fit.

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

Revised on Friday, April 24, 2026