Conditional Blocks
Conditional blocks (if, elif, else) allow executing code only if certain conditions are true.
Syntax
if (condition1) then
elif (condition2) then
elif (condition3) then
else
end
Examples
x = 10
if (x > 0) then
print("Positive")
elif (x < 0) then
print("Negative")
else
print("Zero")
end
age = 25
if (age >= 18) then
if (age >= 21) then
print("Adult (can drink in some countries)")
else
print("Adult (but not everywhere)")
end
else
print("Minor")
end
temperature = 25
is_raining = False
if (temperature > 20 and not is_raining) then
print("Good weather!")
end
Comparison Operators
| Operator |
Example |
Description |
== |
x == 5 |
Equal to |
!= |
x != 5 |
Not equal to |
> |
x > 5 |
Greater than |
< |
x < 5 |
Less than |
>= |
x >= 5 |
Greater than or equal |
<= |
x <= 5 |
Less than or equal |
in |
"a" in "apple" |
Membership check |
Logical Operators
| Operator |
Example |
Description |
and |
x > 0 and x < 10 |
True if both are True |
or |
x == 0 or x == 1 |
True if at least one is True |
xor |
True xor False |
True if exactly one is True |
not |
not (x == 5) |
Negation |
=> |
A => B |
Logical implication (True if A is False or B is True) |