# (if test statement1 \[statement2\]) [GstarCAD 2011](../../../Index.md) → [Developer Reference](../../%28Developer%20Reference%29.md) → [AutoLISP Reference](../%28AutoLISP%20Reference%29.md) → [LISP Functions](%28LISP%20Functions%29.md) <a id="204"></a> ## (if test statement1 \[statement2\]) --- If it is true, do it; otherwise, do something else. --- This function lets you test two conditions: **if** *test* is true, then perform *statement1*, else perform *statement2*. (*Statement2* is optional.) If *test* is true, then LISP returns the value of *statement1*. If *test* is not true, then LISP returns the value of *statement2*. ### Examples | Code | Returns | | --- | --- | | (setq d 9\) | | | (**if** (\>\= d 10\) "Greater") | nil | | (**if** (\>\= d 8\) "Greater") | "Greater" | | (**if** (and (\> d 12\) (\< d 13)) "In range" "Out of range") | "Out of range" | **NOTE** The **if** function only allows a single statement for *statement1* and *statement2*. If you want a multi-line statement, surround them by the [progn](%28progn%20statement1%20statement2%20...%29.md) function, as in the following example: (**if** (\> x 15\) (**progn** ( (setq window 20.0 door 32.0) (command "color" 1\) ) ; end progn ) ; end then ) ; end if **Tell me about...** [(cond (statement1 result1 ...) ...)](%28cond%20%28statement1%20result1%20...%29%20...%29.md) [(repeat number statement1 \[statement2 ...\])](%28repeat%20number%20statement1%20-statement2%20...-%29.md) [(setq symbol1 statement1 \[symbol2 statement2\] ...)](%28setq%20symbol1%20statement1%20-symbol2%20statement2-%20...%29.md) [(while text statement …)](%28while%20text%20statement%20-%29.md) [LISP Compatibility](../LISP%20Compatibility.md) [Programming Overview of LISP (LISt Processing) Language](../Programming%20Overview%20of%20LISP%20%28LISt%20Processing%29%20Language.md) <a id="holding"></a> ## Other versions with matching text [GstarCAD 2012](../../../../2012/Developer%20Reference/AutoLISP%20Reference/LISP%20Functions/%28if%20test%20statement1%20-statement2-%29.md)