The Wayback Machine - https://web.archive.org/web/20240123100821/https://www.geeksforgeeks.org/dotimes-construct-in-lisp/
Open In App
Related Articles

Dotimes Construct in LISP

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

In this article, we will discuss the dotimes loop in LISP. The dotimes is a looping statement used to iterate the elements.  Unlike other looping constructs, it only loops for a specified number of iterations.

Syntax:

(dotimes (n range)
 statements
---------------
--------------
)

where,

  1. n is the starting number-0
  2. The range is the last number till that loop ends.
  3. The statements are the things that are done inside the looping

Example: LISP Program to print cubes of first 20 numbers

Lisp




;define range upto 20
(dotimes (n 20)
  
;display cube of each number
    (print (* n(* n n)))
)


Output:

0 
1 
8 
27 
64 
125 
216 
343 
512 
729 
1000 
1331 
1728 
2197 
2744 
3375 
4096 
4913 
5832 
6859 

Example 2: LISP program to display the sum of each number.

Lisp




;define range upto 20
(dotimes (n 20)
  
;display sum of each number
    (print (+ n n))
)


Output:

0 
2 
4 
6 
8 
10 
12 
14 
16 
18 
20 
22 
24 
26 
28 
30 
32 
34 
36 
38 

Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!


Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 22 Sep, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials