Skip to main content

Yield & Return

Coco uses named return values. Set them with yield, assignment, or return.

Setting Return Values

endpoint GetSender() -> (addr Identifier):
// These are equivalent:
yield addr Sender
addr = Sender

Early Return

Use return to exit immediately with values:

endpoint CheckAll(items []U64, lookup Map[U64]String) -> (valid Bool):
for item in items:
if !lookup[item]?:
return (valid: false) // Exit early
valid = true

No Return Value

Use pass for endpoints with no outputs:

endpoint DoNothing():
pass

Yield Variants

// Single value
yield count 42

// Brace form — set multiple return values at once
yield {count: 42, name: "Alice"}

// From variable
yield out some_variable

Return Variants

// Parenthesized named return (most common)
return (name: value, supply: amount)

// Bare return — exits without setting new values
return

// Single-name return without parens
return name value

Summary

KeywordPurpose
yield name valueSet named return value, continue execution
yield {k: v, ...}Set multiple return values at once, continue
=Assign to return value (same as yield)
return (name: value)Set value and exit immediately
returnExit without setting values
passDo nothing (for empty endpoints)