Next: , Previous: , Up: Iteration Control   [Contents][Index]


15.25.6.4 ’for-as-on-list’

This is the third of seven ‘for/as’ syntaxes

for var [type-spec] on expr1 [by step-fun]
 as var [type-spec] on expr1 [by step-fun]

This construct iterates over the contents of a list (using the successive tails of the list each iteration).

;;; Collect successive tails of a list.
(loop for sublist on '(a b c d)
      collect sublist)
;;; Print a list by using destructuring with the loop keyword ON.
(loop for (item) on '(1 2 3)
      do (print item))  ;Prints 3 lines