This topic is about LISP – Dolist Construct.
The dolist construct allows iteration through each element of a list.
For example, Create a new source code file named main.lisp and type the following code in it −
(dolist (n '(1 2 3 4 5 6 7 8 9)) (format t "~% Number: ~d Square: ~d" n (* n n)) )
When you click the Execute button, or type Ctrl+E, LISP executes it immediately and the result returned is −
Number: 1 Square: 1 Number: 2 Square: 4 Number: 3 Square: 9 Number: 4 Square: 16 Number: 5 Square: 25 Number: 6 Square: 36 Number: 7 Square: 49 Number: 8 Square: 64 Number: 9 Square: 81
In this topic we learned about LISP – Dolist Construct. To learn more, Click Here.