8.2. yield statements

Example 8-2. Examples:

yield x
yield_statement ==>
        yield [ expression ]

yield statements are used to return control to a loop and may appear only in iterator definitions. The expression clause must be present if the iterator has a return value and must be absent if it does not. If expression is present, then its type must be a subtype of the return type of the iterator. Execution of a yield statement causes the expression to be evaluated and its value to be returned to the caller of the iterator in which it appears. Yield is not permitted within a protect statement (see See protect statements). Yield causes assignment to out and inout arguments in the caller (See Method call expressions).