Conditional
Aqua supports branching, you can:
- Check boolean expression with if
- Recover from error with tryorotherwise
- Return different results with conditional return
Contract
- The second branch of the conditional operator is executed if and only if the first block failed.
- The second branch has no access to the first branch's data.
- A conditional block is considered "executed" if and only if any branch was executed successfully.
- A conditional block is considered "failed" if and only if the second (recovery) branch failed.
Conditional operations
if
The first branch of the conditional operator, executed only if the condition holds.
aqua
aqua
Any expression that produces bool is acceptable as a condition.
if corresponds to match, mismatch extension of π-calculus.
else
The second branch of if, executed only in case the condition does not hold.
aqua
aqua
If you want to set a variable based on condition, see conditional return.
try
Tries to perform operations, swallows produced error (if there's no catch, otherwise executes catch).
aqua
aqua
catch
Catches the standard error from the try block.
aqua
aqua
Type of e is:
aqua
aqua
otherwise
You may add otherwise to provide recovery for any block or expression:
aqua
aqua
Conditional return
In Aqua, functions may have only one return expression, which is the very last.
So to get the value based on condition, we need to use a writeable collection.
aqua
aqua