Choose from several cases
Check a value against several choices. Give it a default result for anything outside the listed cases.
Simple example
Choose the second price.
Start2
Result4
def main() raises:
var price = 6
if 2 == 1:
price = 2
elif 2 == 2:
price = 4
print(price)
4
Advertisements
Everyday examples
The bus charges 2 coins in zone 1, 4 in zone 2 and 6 in the other zones. What is the fare in zone 3?
StartZone 3
Result6
def main() raises:
var price = 6
if 3 == 1:
price = 2
elif 3 == 2:
price = 4
print(price)
6