LISP - Dotimes Construct



The dotimes construct allows looping for some fixed number of iterations.

For example, Create a new source code file named main.lisp and type the following code in it −

(dotimes (n 11)
   (print n) (prin1 (* n n))
)

When you click the Execute button, or type Ctrl+E, LISP executes it immediately and the result returned is −

0 0
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
10 100
lisp_loops.htm
Advertisements