Loop For Construct in LISP Last Updated : 04 Jan, 2023 Comments Improve Suggest changes Like Article Like Report The loop for construct in common LISP is used to iterate over an iterable, similar to the for loop in other programming languages. It can be used for the following: This is used to set up variables for iteration.It can be used for conditionally terminate the iteration.It can be used for operating on the iterated elements. The loop For construct can have multiple syntaxes. Syntaxes: To iterate over a list:(loop for variable in input_list do (statements/conditions) ) Here, input_list is the list that is to be iterated.The variable is used to keep track of the iteration.The statements/conditions are used to operate on the iterated elements.To iterate over the given range:(loop for variable from number1 to number2 do (statements/conditions) ) Here, The number1 is the starting number and number 2 is the ending number from the range.The variable is used to keep track of the iteration.The statements/conditions are used to operate on the iterated elements. Example: LISP Program to print numbers in a range Lisp ;range from 1 to 5 (loop for i from 1 to 5 ;display each number do (print i) ) Output: 1 2 3 4 5 Example 2: LISP Program to iterate elements over a list. Lisp ;list with 5 numbers (loop for i in '(1 2 3 4 5) ;display each number do (print i) ) ;list with 5 strings (loop for i in '(JAVA PHP SQL HTML CSS) ;display each string do (print i) ) Output: 1 2 3 4 5 JAVA PHP SQL HTML CSS Example 3: LISP Program to iterate each number from range and perform increment and decrement operations. Lisp ;list with 5 numbers (loop for i in '(1 2 3 4 5) ;display each number by incrementing each number by 5 do (print (incf i 5)) ) ;list with 5 numbers (loop for i in '(1 2 3 4 5) ;display each number by decrementing each number by 5 do (print (decf i 5)) ) Output: 6 7 8 9 10 -4 -3 -2 -1 0 Comment More infoAdvertise with us Next Article Loop For Construct in LISP M manojkumarreddymallidi Follow Improve Article Tags : LISP LISP-Basics Similar Reads Loop Construct in LISP In this article, we will discuss Loop Construct. This Construct is used to iterate the data until it finds the return statement. And then it will stop iterating and return the results. Syntax: (loop (statements) condition return ) where, loop is the keywordstatements are used to iterate the loopcond 2 min read Do Construct in LISP In this article, we will discuss the Do Construct in LISP. Do construct is used to perform an iteration in a structured format. Syntax: (do ((variable1 value1 new updated value 1) (variable2 value2 new updated value 2) ------------------------------- ------------------------------- (variable n value 2 min read If Construct in LISP In this article, we will discuss the if construct in LISP. The if is a decision-making statement used to check whether the condition is right or wrong. The if the condition is right, then it will go inside the if block and execute the statements under if block. Otherwise, the statements are not exec 2 min read Dolist Construct in LISP DoList in Common LISP is a looping statement used to iterate the elements in a list. Syntax: (dolist input_list) statements... ) Here, The input_list contains the list of elements that are iterated.The statements are present in the loop. Example 1: LISP Program to iterate the list of elements from 1 2 min read Dotimes Construct in LISP 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, n is the sta 1 min read Like