HomeManualTopicsTypesSymbols

std::if

classic if; can be used as a function or a procedure

Parameters

condition
true or false
then_part
the function to be evaluated if the condition is true
else_part
the function to be evaluated if the condition is false

Results

None

Description

The "then-part"- and "else-part" functions can return any number of results (including none). But both should return the same number of results.

Example

# "if" as a procedure $x 5 if x > 3: println! "x is larger than 3" : println! "x is not larger than 3"

Output

x is larger than 3

Example

# "if" as a function $x 5 println! if x > 3 -> "x is larger than 3" -> "x is not larger than 3"

Output

x is larger than 3

Example

# "if" with multiple results $x 5 if $a $b x > 7 -> x*x x+1 -> 2*x*x x+3 print! " a = @(a) b = @(b)

Output

a = 50 b = 8

Topic

Branches

See also

std::if_not can be used as a function or a procedure
std::on if the specified condition is true then perform the specified action
std::on_not if the specified condition is false then perform the specified action
std::cond a multiway conditional expression or statement
std::case a multiway conditional expression or statement
std::and "short cut" and-operation
std::or "short cut" or- operation
std::default_value returns the first argument if it is defined or else the second argument

Implemented by

std_types::false evaluates the else-part and returns its result(s)
std_types::true evaluates the then-part and returns its result(s)