if ... then ... else if | switch ... case
Create multiple conditional statements by concatenating if-then-else blocks. Write another if
after else
for another condition and so on—continue for as long as needed.
As in the previous example, use the Total number field again and insert the following script into a Formula field:
Result: In the function field you will receive the response "Cash"
, "Card"
, or "Please enter an amount!"
according to the input.
Replace multiple nested conditional statements with switch ... case
. Use this statement to query an expression (switch ...
) for possible results (case ...:
) and set a default behavior (default:
) if the expression does not correspond to any of the results.
Depending on the result, assign the next step accordingly. This helps avoid deeply nested if statements.
Tip: switch ... case
works best when the queried value is a choice field.
There's a choice field Payment method with the following options:
Cash
Bank transfer
Direct debit
Insert the following script into a formula field to display info about the selected payment type:
Result: Based on your entry in the Payment method choice field, exactly one of the following info is visible in your formula field:
Payment method: Cash
Payment method: Bank transfer. Only from €30.
Payment method: Direct debit. Do not forget your signature.
Please select a payment method.
Do you want to dive deeper into the if ... then ... else
topic? Take a look at the corresponding part of our video tutorial.
Do you want to dive deeper into the switch
topic? Take a look at the corresponding part of our video tutorial.