Conditional
Aqua supports branching: you can return one value or another, recover from the error, or check a boolean expression.
Contract
The second branch of the conditional operator is executed if and only if the first block failed.
The second block has no access to the first block's data.
A conditional block is considered "executed" if and only if any inner block was executed successfully.
A conditional block is considered "failed" if and only if the second (recovery) block fails to execute.
Block of code is any number of lines on the same indentation level or deeper
Conditional operations
try
Tries to perform operations, or swallows the error (if there's no catch, otherwise after the try block).
catch
Catches the standard error from try
block.
Type of e
is:
if
If corresponds to match
, mismatch
extension of π-calculus.
Currently, you may only use one ==
, !=
operator in the if
expression, or compare with true.
Both operands can be variables.
else
Just the second branch of if
, in case the condition does not hold.
If you want to set a variable based on condition, see Conditional return.
otherwise
You may add otherwise
to provide recovery for any block or expression:
Conditional return
In Aqua, functions may have only one return expression, which is very last. And conditional expressions cannot define the same variable:
So to get the value based on condition, we need to use a writeable collection.
Last updated
Was this helpful?