if
if(g_conditiong_thenExpression[g_elseExpression] ) =>g_resultif(g_conditiontheng_thenExpr1... [ elseg_elseExpr1... ] ) =>g_result
Description
Selectively evaluates two groups of one or more expressions. This is a syntax form.
if(g_conditiong_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_conditiontheng_thenExpr1... [ elseg_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
Value Returned
|
The value of g_thenExpression if g_condition has a non- |
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
Return to top