Case Construct in LISP Last Updated : 24 Dec, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will discuss the case construct in LISP. This is used to check multiple test conditions at a time, unlike cond, if and when it allows multiple conditions. Syntax: (case (key_value) ((key1) (statement 1 .............. statement n) ) ((key2) (statement 1 .............. statement n) ) ................ ((keyn) (statement 1 .............. statement n) ) Here, key_value is the numeric value taken an inputkeys are the different conditions to test particular condition specified in keys Example 1: LISP Program to get the particular number when the number is given. Lisp ;define value to 2 (setq val1 2) ;define 5 cases from 1 to 5 (case val1 (1 (format t "you selected number 1")) (2 (format t "you selected number 2")) (3 (format t "you selected number 3")) (4 (format t "you selected number 4")) (5 (format t "you selected number 5")) ) Output: you selected number 2 Example 2: LISP Program to perform an arithmetic operation when a particular key is chosen. Lisp ;define value1 to 10 (setq val1 10) ;define value2 to 20 (setq val2 20) ;set input to 1 (setq input 1) ;define 4 cases to perform each arithmetic operation (case input ;condition to perform addition (1 (print (+ val1 val2))) ;condition to perform subtraction (2 (print (- val1 val2))) ;condition to perform multiplication (3 (print (* val1 val2))) ;condition to perform division (4 (print (/ val1 val2))) ) Output: 30 Now if we set input to 3: Lisp ;define value1 to 10 (setq val1 10) ;define value2 to 20 (setq val2 20) ;set input to 3 (setq input 3) ;define 4 cases to perform each arithmetic operation (case input ;condition to perform addition (1 (print (+ val1 val2))) ;condition to perform subtraction (2 (print (- val1 val2))) ;condition to perform multiplication (3 (print (* val1 val2))) ;condition to perform division (4 (print (/ val1 val2))) ) Output: 200 Comment More infoAdvertise with us Next Article Case Construct in LISP S saisravanprojects Follow Improve Article Tags : LISP LISP-Functions Similar Reads 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 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 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 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 When Construct in LISP In this article, we will discuss the when construct. The when is a decision-making statement used to specify the decisions. It is similar to conditional statements. Syntax: (when (condition) (statements) ) where, condition is a test statement used to teststatements are the actions that will depend o 2 min read Like