Next: End-Test Control, Previous: Loop Constructs, Up: Loop [Contents][Index]
Iteration control clauses allow you to direct loop iteration.
The loop keywords:
as
for
repeat
designate iteration control clauses. They must precede any other loop clauses except
initially
,
with
, and
named
since they establish variable bindings.
Iteration control clauses differ with respect to the specification of
of loop variables. When iteration control clauses are used in a loop, termination tests in the loop body are evaluated before any other loop body code is executed.
The for
and as
keywords are synonyms, and the clauses iterate by
There are seven syntactic representations for these constructs.
var
can be specified by
the optional type-spec
argument.
var
is a destructuring list, the data type specified by the
type-spec
argument must appropriately match the elements of the list.
All variables are initialized in the loop prologue.
Iteration clauses by themselves do not cause the Loop Facility to return values, but they can be used in conjunction with value-accumulation clauses to return values.
The scope of the variable binding is lexical unless it is proclaimed special; thus, the variable can be accessed only by expressions that lie textually within the loop. Stepping assignments are made in the loop body before any other expressions are evaluated in the body.
and
ConstructIf you use multiple iteration clauses to control iteration,
occur sequentially by default.
and
You can use the and
construct to connect two or more iteration clauses when
sequential binding and stepping are not necessary. The iteration behavior of
clauses joined by and
is analogous to the behavior of the Common Lisp macro
do
relative to do*
.
for-as ::= {for | as} for-as-subclause {and for-as-subclause}* for-as-subclause ::= for-as-arithmetic | for-as-in-list | for-as-on-list | for-as-equals-then | for-as-across | for-as-hash | for-as-package for-as-arithmetic ::= var [type-spec] [{from | downfrom | upfrom} expr1 ] [{to | downto | upto | below | above} expr2] [by expr3] for-as-in-list ::= var [type-spec] in expr1 [by step-fun] for-as-on-list ::= var [type-spec] on expr1 [by step-fun] for-as-equals-then ::= var [type-spec] = expr1 [then step-fun] for-as-across ::= var [type-spec] across vector for-as-hash ::= var [type-spec] being {each | the} {hash-key | hash-keys | hash-value | hash-values} {in | of} hash-table [using ({hash-value | hash-key} other-var)] for-as-package ::= var [type-spec] being {each | the} for-as-package-keyword {in | of} package for-as-package-keyword ::= symbol | present-symbol | external-symbol | symbols | present-symbols | external-symbols
Next: End-Test Control, Previous: Loop Constructs, Up: Loop [Contents][Index]