If |
Flow control | |
| Aptilis 1 | ||
If
if expr
line of code
line of code
.
.
end if
Or:
if expr
line of code
line of code
else
line of code (alternate)
line of code (alternate)
end if
if allows your programme to execute one
or several lines only if a condition is true.
With 'else' you can indicate some alternate lines to run
when the condition is false.
Example 1:
a = 12
if a < 20
print("a is less than 20")
end if
Result:
a is less than 20 |
Example 2:
a = 12
if a < 20
print("a is less than 20")
else
print("a is greater than or equal to 20")
end if
Result:
a is less than 20 |
Example 3:
a = 21
if a < 20
print("a is less than 20")
else
print("a is greater than or equal to 20")
end if
Result:
a is greater than or equal to 20 |
Notes:
