Iteration Control
Most of the so-called iteration control clauses start with the loop keyword for
, or its synonym as
,2 followed by the name of a variable. What follows after the variable name depends on the type of for
clause.
The subclauses of a for
clause can iterate over the following:
- Ranges of numbers, up or down, by specified intervals
- The individual items of a list
- The cons cells that make up a list
- The elements of a vector, including subtypes such as strings and bit vectors
- The pairs of a hash table
- The symbols in a package
- The results of repeatedly evaluating a given form
A single loop can have multiple for
clauses with each clause naming its own variable. When a loop has multiple for
clauses, the loop terminates as soon as any for
clause reaches its end condition. For instance, the following loop:
(loop
for item in list
for i from 1 to 10
do (something))
will iterate at most ten times but may stop sooner if list
contains fewer than ten items.
当前内容版权归 gigamonkeys 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 gigamonkeys .