If-then-else expressions almost resemble normal, spoken English. You use them to tell atfinity that
ifa condition is met
The expression can also contain as many
thenexpression parts as you like. The expression closes with the keyword
if [condition] then
elif [condition] then
conditionneeds to evaluate to true or false. It could be a comparison (
p.age >= 18) or a boolean yes/no question (
- Both expressions have to return the same type of value, for example a number.
If you have some programming experience, you may be surprised that the
elseis not optional. Please note though, that
ifin atfinity is an expression, so it always needs to return a value.
p is Person
if p.loves_danger then high_risk else low_risk end
To determine the risk level of a person, inquire whether it is true or false that the person loves danger.
- True: the expression returns what's behind
then: the person is deemed of high risk level.
- False: the expression returns what's behind
else: the person's risk level is marked as low.
holiday is Holiday
if holiday.weather = sunshine then
elif holiday.weather = rain then
elif holiday.budget > 1000 then