Conditional expressions
Conditional expressions are constructed using the @if
, @elseif
, and @else
keywords.
Syntax
Standalone @if
@if CONDITION1: {
# ...
}
@if
-@elseif
chaining
@if CONDITION1: {
# ...
} @elseif CONDITION2: {
# ...
} @elseif CONDITION3: {
# ...
}
@if
-@else
chaining
@if @CONDITION1: {
# do something when <condition> is true
} @else: {
# do something when <condition> is false
}
@if
-@elseif
-@else
chaining
@if CONDITION1: {
# ...
} @elseif CONDITION2: {
# ...
} @elseif CONDITION3: {
# ...
} @else: {
# ...
}
Truthiness
All condition values are coerced to bool
using truthiness rules.
The truthiness rules are as follows:
Data type | Evaluation |
---|---|
bool | Unchanged. |
string , list , map , range | @true if nonzero length; otherwise, @false . |
float , int | @true if nonzero; otherwise, @false . |
nothing | Always @false . |
selector , function | Always @true . |