Next: Accumulation Clauses, Previous: For Clauses, Up: Loop Facility [Contents][Index]
Aside from for clauses, there are several other loop clauses
that control the way the loop operates. They might be used by
themselves, or in conjunction with one or more for clauses.
repeat integerThis clause simply counts up to the specified number using an internal temporary variable. The loops
(cl-loop repeat (1+ n) do …) (cl-loop for temp to n do …)
are identical except that the second one forces you to choose a name for a variable you aren’t actually going to use.
while conditionThis clause stops the loop when the specified condition (any Lisp
expression) becomes nil. For example, the following two
loops are equivalent, except for the implicit nil block
that surrounds the second one:
(while cond forms…) (cl-loop while cond do forms…)
until conditionThis clause stops the loop when the specified condition is true,
i.e., non-nil.
always conditionThis clause stops the loop when the specified condition is nil.
Unlike while, it stops the loop using return nil so that
the finally clauses are not executed. If all the conditions
were non-nil, the loop returns t:
(if (cl-loop for size in size-list always (> size 10)) (only-big-sizes) (some-small-sizes))
never conditionThis clause is like always, except that the loop returns
t if all conditions were false, or nil otherwise.
thereis conditionThis clause stops the loop when the specified form is non-nil;
in this case, it returns that non-nil value. If all the
values were nil, the loop returns nil.
iter-by iteratorThis clause iterates over the values from the specified form, an iterator object. See (see Generators in GNU Emacs Lisp Reference Manual).
Next: Accumulation Clauses, Previous: For Clauses, Up: Loop Facility [Contents][Index]