Next: ’for-as-across’, Previous: ’for-as-on-list’, Up: Iteration Control [Contents][Index]
This is the fourth of seven ‘for/as’ syntaxes.
for var [type-spec] = expr1 [then expr2] as var [type-spec] = expr1 [then expr2]
This construct
var
by setting it to the result of evaluating
expr1
on the first iteration,
expr2
on the second and
subsequent iterations.
expr2
is omitted, the construct uses expr1
on the second and
subsequent iterations. When expr2
is omitted, the expanded code shows the
following optimization:
;;; Sample original code: (loop for x = expr1 then expr2 do (print x)) ;;; The usual expansion: (tagbody (setq x expr1) tag (print x) (setq x expr2) (go tag)) ;;; The optimized expansion: (tagbody tag (setq x expr1) (print x) (go tag))
;;; Collect some numbers. (loop for item = 1 then (+ item 10) repeat 5 collect item)