1.3.0 permalink Arrow_down_16x16

dotimes

clojure.core

  • (dotimes bindings & body)
bindings => name n

Repeatedly executes body (presumably for side-effects) with name
bound to integers from 0 through n-1.

1 Example top

  • user=> (dotimes [n 5] (println "n is" n))
    n is 0
    n is 1
    n is 2
    n is 3
    n is 4
    nil
Log in to add / edit an example.

See Also top

  • 0
    clojure.core/repeat

    Returns a lazy (infinite!, or length n if supplied) sequence of xs.

  • 0
    clojure.core/for

    List comprehension. Takes a vector of one or more binding-form/col

  • 0
    clojure.core/doseq

    Repeatedly executes body (presumably for side-effects) with binding

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:2894 top

(defmacro dotimes
  "bindings => name n

  Repeatedly executes body (presumably for side-effects) with name
  bound to integers from 0 through n-1."
  {:added "1.0"}
  [bindings & body]
  (assert-args dotimes
     (vector? bindings) "a vector for its binding"
     (= 2 (count bindings)) "exactly 2 forms in binding vector")
  (let [i (first bindings)
        n (second bindings)]
    `(let [n# (long ~n)]
       (loop [~i 0]
         (when (< ~i n#)
           ~@body
           (recur (unchecked-inc ~i)))))))
Vars in clojure.core/dotimes:
Used in 0 other vars

Comments top

No comments for dotimes. Log in to add a comment.