The Parts of a LOOP

You can do the following in a **LOOP**:

  • Step variables numerically and over various data structures
  • Collect, count, sum, minimize, and maximize values seen while looping
  • Execute arbitrary Lisp expressions
  • Decide when to terminate the loop
  • Conditionally do any of these

Additionally, **LOOP** provides syntax for the following:

  • Creating local variables for use within the loop
  • Specifying arbitrary Lisp expressions to run before and after the loop proper

The basic structure of a **LOOP** is a set of clauses, each of which begins with a loop keyword.1 How each clause is parsed by the **LOOP** macro depends on the keyword. Some of the main keywords, which you saw in Chapter 7, are for, collecting, summing, counting, do, and finally.