Next: , Previous: , Up: Loop   [Contents][Index]


15.25.6 Iteration Control

Iteration control clauses allow you to direct loop iteration.

The loop keywords:

designate iteration control clauses. They must precede any other loop clauses except

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.

Iteration Control Clause Summary

The for and as keywords are synonyms, and the clauses iterate by

7 Syntactic Representations

There are seven syntactic representations for these constructs.

  1. arithmetic
  2. in list
  3. on list
  4. equals then
  5. across
  6. hash
  7. package

Data Types

Initialization and Return Values

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.

Scope of the Variable Binding is Lexical by Default

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.

Multiple Iteration Clauses and and Construct

Sequential Binding by Default

If you use multiple iteration clauses to control iteration,

occur sequentially by default.

Parallel Binding using 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*.

Syntax of Iteration Control Clauses

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]