Do Construct in LISP Last Updated : 09 Nov, 2021 Comments Improve Suggest changes Like Article Like Report 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 n new updated value n) ...) (test statements) ) Here, variables are the input values.new updated values are the values that are updated based on the condition given in the value.test statements are to be executed at the final. Example 1: LISP Program to get value increment and decrement display until the given condition Lisp ;define value 1 to 0 ;define value 2 to 30 (do ((val1 0 (+ 2 val1)) (val2 24 ( - val2 2))) ;display both values until value1 is equal to value2 ;by incrementing value1 by 2 ;by decrementing value2 by 2 ((= val1 val2)(- val2 val2)) ;display (format t "~% value 1 = ~d and value 2 = ~d" val1 val2) ) Output: value 1 = 0 and value 2 = 24 value 1 = 2 and value 2 = 22 value 1 = 4 and value 2 = 20 value 1 = 6 and value 2 = 18 value 1 = 8 and value 2 = 16 value 1 = 10 and value 2 = 14 Example 2: LISP Program to display all till value 1 is greater than value 2 by performing increment and decrement operations Lisp ;define value 1 to 0 ;define value 2 to 30 (do ((val1 0 (+ 2 val1)) (val2 24 ( - val2 2))) ;display both values until value1 is greater than value2 ;by incrementing value1 by 2 ;by decrementing value2 by 2 ((> val1 val2)(- val2 val2)) ;display (format t "~% value 1 = ~d and value 2 = ~d" val1 val2) ) Output: value 1 = 0 and value 2 = 24 value 1 = 2 and value 2 = 22 value 1 = 4 and value 2 = 20 value 1 = 6 and value 2 = 18 value 1 = 8 and value 2 = 16 value 1 = 10 and value 2 = 14 value 1 = 12 and value 2 = 12 Comment More infoAdvertise with us Next Article Dolist Construct in LISP S saisravanprojects Follow Improve Article Tags : LISP LISP-Control-Structures Similar Reads 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 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 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 Loop For Construct in LISP 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 2 min read 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 Cond Construct in LISP In this article, we will discuss cond construct in LISP. The cond is a decision-making statement used to make n number of test conditions. It will check all the conditions. Syntax: (cond (condition1 statements) (condition2 statements) (condition3 statements) ... (conditionn statements) ) Here, The c 2 min read Like