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

If Construct in LISP

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

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 executed.

Syntax:

(if (condition) then (statement 1).....(statement  n))

Here, then is an optional keyword used inside the if statement.

Example 1: LISP Program to check conditions with operators

Lisp




;define value to 100
(setq val1 100)
  
;check the number is equal to 100
(if (= val1 100)
   (format t "equal to 100"))
     
(terpri)
  
;check the number is greater than to 50
(if (> val1 50)
   (format t "greater than 50"))
    
(terpri)
  
;check the number is less than to 150
(if (< val1 150)
   (format t "less than 150"))


Output:

equal to 100
greater than 50
less than 150

Example 2:

Lisp




;define value to 230
(setq val1 230)
  
;check the number is equal to 100
(if (= val1 100)
   (format t "equal to 100"))
     
(terpri)
  
;check the number is greater than to 50
(if (> val1 50)
   (format t "greater than 50"))
    
(terpri)
  
;check the number is less than to 150
(if (< val1 250)
   (format t "less than 250"))


Output:

greater than 50
less than 250

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 : 09 Nov, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials