Function: dotimes
dotimes is a macro defined in subr.el.gz.
Signature
(dotimes (VAR COUNT [RESULT]) BODY...)
Documentation
Loop a certain number of times.
Evaluate BODY with VAR bound to successive integers running from 0, inclusive, to COUNT, exclusive.
Finally RESULT is evaluated to get the return value (nil if RESULT is omitted). Using RESULT is deprecated, and may result in compilation warnings about unused variables.
This macro has :around advice: cl--wrap-in-nil-block.
Probably introduced at or before Emacs version 21.1.
Source Code
;; Defined in /usr/src/emacs/lisp/subr.el.gz
(defmacro dotimes (spec &rest body)
"Loop a certain number of times.
Evaluate BODY with VAR bound to successive integers running from 0,
inclusive, to COUNT, exclusive.
Finally RESULT is evaluated to get the return value (nil if
RESULT is omitted). Using RESULT is deprecated, and may result
in compilation warnings about unused variables.
\(fn (VAR COUNT [RESULT]) BODY...)"
(declare (indent 1) (debug dolist))
(let ((var (nth 0 spec))
(end (nth 1 spec))
(upper-bound (make-symbol "upper-bound"))
(counter (make-symbol "counter")))
`(let ((,upper-bound ,end)
(,counter 0))
(while (< ,counter ,upper-bound)
(let ((,var ,counter))
,@body)
(setq ,counter (1+ ,counter)))
,@(if (cddr spec)
;; FIXME: This let often leads to "unused var" warnings.
`((let ((,var ,counter)) ,@(cddr spec)))))))