Returning or Yielding Values
In Coco, all callable return parameters are declared before the function execution. The logic can either set individual values to the output values with yield
or all of them at once with return.
When an output value is set using yield
, the control flow is unaffected but when using return
the control flow exits the function execution.
A less verbose way to set the value of a return is a simple assignment, like out = 5
Return values can only be set, trying to read them results in compiler error.
No Op Execution
The pass
statement can be used for no op code execution for a given scope.
coco Yielding
func SenderAddress() -> (addr Address):
// assignment can be used instead of yield
addr = Address(Sender)
func MapCheck(a []U64, m Map[U64]String) -> (has Bool):
memory has2 = a[2]?
has = m[a[1]]?
// if !has: would produce a compiler error
// as reading return values is not allowed
if !has2:
return {has:has2}
yield has = m[a[2]]?
func DoNothing():
pass