- The dotimes construct. In the example below,
there is a list containing 3 atoms to the right of
dotimes: (1) i, the loop index variable, initialized
to 0, (2) 10, the upper bound for i, when i equals 10,
the loop terminates, and (3) sum, an optional return value for
the loop.
(setf sum 0) ;; declare as a local variable above!
(dotimes (i 10 sum)
(setf sum (+ sum i))
)
- The dolist construct.
In the example below, there is a list containing 3
atoms to the right of dolist: (1) item, the loop index
variable, (2) the list '(1 2 3) of which item successively takes
each value, and (3) sum, an optional return value for
the loop.
(set sum 0) ;; declare as a local variable above!
(dolist (item '(1 2 3) sum)
(setf sum (+ sum item))
)
- The do construct.
(do ;; abstract version
;; INITIAL-VALUE is optional
;; UPDATE-TECHNIQUE is optional
;; INTERMEDIATE-FORMS are optional
;; RESULT is optional
(
(local-variable-1 initial-value update-technique)
...
(local-variable-n initial-value update-technique)
)
( termination-test intermediate-forms result )
loop-body
)
(do ;; concrete example
(
(sum 0)
(counter 0 (+ counter 1))
)
( (>= counter 10) sum )
(setf sum (+ sum counter))
)
- The do* construct. It is identical to do,
except local variables are assigned values sequentially
instead of in parallel. This is very similar to the difference
between let and let*.