pocketlang/test/lang/controlflow.pk
2021-06-02 17:32:13 +05:30

52 lines
986 B
Plaintext

## If statements.
variable = null ## Will be changed by the control flow.
unreachable = func assert(false, 'Unreachable') end
if true then variable = 42 else unreachable() end
assert(variable == 42, 'If statement failed.')
if false then unreachable()
elif true then variable = null
else unreachable() end
assert(is_null(variable), 'Elif statement failed.')
if false then unreachable()
elif false then unreachable()
elif false then unreachable()
else variable = "changed" end
assert(variable == "changed", 'Else statement failed.')
if false then unreachable()
elif true
if false
unreachable()
elif true
variable = 123
else
unreachable()
end
end
assert(variable == 123, 'Nested if statement failed.')
## While statements
while true
variable = 1212
if true then break end
end
assert(variable == 1212)
while true
variable = 22
if true then elif false then end
if false
elif true
variable += 2300
end
variable += 1
break
end
assert(variable == 2323)