Книга: Practical Common Lisp

Iteration Control

Iteration Control

Most of the so-called iteration control clauses start with the loop keyword for, or its synonym as,[235] 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.

Оглавление книги


Генерация: 0.844. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз