Product Documentation
Cadence SKILL Language Reference
Product Version IC23.1, November 2023

if

if( 
g_condition 
g_thenExpression 
[ g_elseExpression ] 
) 
=> g_result
if( 
g_condition 
then g_thenExpr1 ... 
[ else g_elseExpr1 ... ] 
) 
=> g_result

Description

Selectively evaluates two groups of one or more expressions. This is a syntax form.

if( g_condition g_thenExpression [ g_elseExpression ] ) 
=> g_result

The if form evaluates g_condition, typically a relational expression, and executes g_thenExpression if the condition is true (that is, its value is non-nil); otherwise, g_elseExpression is executed. The value returned by if is the value of the corresponding expression evaluated. The if form can therefore be used to evaluate expressions conditionally.

if( g_condition then g_thenExpr1 ... [ else g_elseExpr1 ... ] ) 
=> g_result

The second form of if uses the keywords then and else to group sequences of expressions for conditional execution. If the condition is true, the sequence of expressions between then and else (or the end of the if form) is evaluated, with the value of the last expression evaluated returned as the value of the form. If the condition is nil instead, the sequence of expressions following the else keyword (if any) is evaluated instead. Again, the value of the last expression evaluated is returned as the value of the form.

Arguments

g_condition

Any SKILL expression.

g_thenExpression

Any SKILL expression.

g_elseExpression

Any SKILL expression.

Value Returned

g_result

The value of g_thenExpression if g_condition has a non-nil value. The value of g_elseExpression is returned if the above condition is not true.

Examples

x = 2
if( (x > 5) 1 0)
=> 0   ; Returns 0 because x is less than 5.
a = "polygon"
if( (a == "polygon") print(a) )
"polygon"   ; Prints the string polygon.
=> nil ; Returns the result of print.
x = 5
if( x "non-nil" "nil" )
=> "non-nil" ; Returns "non-nil" because x was not
; nil. If x was nil then "nil" would be
; returned.
x = 7
if( (x > 5) then 1 else 0)
=> 1 ; Returns 1 because x is greater than 5.
if( (x > 5)
then println("x is greater than 5")
x + 1
else print("x is less ")
x - 1)
x is greater than 5       ; Printed if x was 7.
=> 8   ; Returned 8 if x was 7.

Related Topics

Flow Control Functions

cond

foreach

unless

while


Return to top
 ⠀
X