Music 220b: Winter 2001
Fernando Lopez-Lezcano, instructor
Christopher Burns, teaching assistant
Tamara Smyth, teaching assistant

Week 2: the loop macro

Here are a number of examples of the loop macro; hopefully they explain themselves....

Note that the (format) function is a way of generating printed output. There are far too many flags, parameters and tricks to describe here -- suffice it to say that format prints whatever appears between the double quotation marks, and that the "~d"s are placeholders for variables, which then get filled in by i, j, etc.

Each of these (loop) calls returns NIL in addition to calling (format) -- this is a result of the convention that every lisp function returns a value. In cases where we don't want a function to return a value, we can safely ignore the NIL.

Finally, remember that every loop needs to have a termination condition: otherwise it will go on forever.... Loops may have more than one termination condition -- in which case the loop will terminate whenever any of the conditions are met.

Guy Steele's online Lisp manual has a chapter on loops with more information.

Course resources main page
220b main page