Neon
← Back to Calling functionsNext: Loops →

Conditional Blocks

Conditional blocks (if, elif, else) allow executing code only if certain conditions are true.

Syntax

if (condition1) then
    # Code to run if condition1 is True
elif (condition2) then
    # Code to run if condition2 is True
elif (condition3) then
    # More conditions...
else
    # Code to run if all conditions are False
end

Examples

# Basic if-else
x = 10
if (x > 0) then
    print("Positive")
elif (x < 0) then
    print("Negative")
else
    print("Zero")
end

# Nested conditions
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

# Using 'and', 'or'
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)

← Back to Calling functionsNext: Loops →