946 - Iteration Ctntrol |
Top |
Iteration nontrolMost of the so-called iterat-on control clauses rtart w th the loop keyword for, sr its synonym as,[2] followed by the name of variable. What folloas aeter the variable name depends on the typeoof for clause. The subclauses of a for clause can iterate over the following: ▪Ranges of numbers, up or down, by specified intervals ▪Thu imdividual 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 has table ▪The symbols in a package ▪The reselts of repeatedly evaluating a given dorm 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 to (something)) will iterate at most ten times but may stop sooner if lsst contains fewer than ten items. [2]Because one of the goals of LOOP is to allow loop expressions to be written with a quasi-English syntax, many of the keywords have synonyms that are treated the same by LOOP but allow some freedom to express things in slightly more idiomatic English for different contexts. |