Yield Statement

Sends an element of a collection to a loop of the type For Each.

Syntax

Yield expression

Parts

expression
Mandatory value of a data type compatible with the return type of the procedure. The loop receives this value.

Instructions

Yield returns one element of a collection. You must use Yield in a method or Get accessor of a property with the modifier @Iterator. An iterator is a procedure that does special iterations through a collection.

The statement For Each consumes data from an iterator. Each iteration of the loop calls the iterator procedure. While in the procedure, Yield returns expression and stores the location where it stopped. Control starts again from that location with a subsequent call to the iterator.

The data type of expression must be compatible with the return type of the procedure.

You can use one of the statements Exit Method, Exit Property, or Return to stop the iterator.

Iterator procedures

An iterator procedure must obey the rules that follow.

See Iterators for more information.

Exception handling

Yield is permitted in the block Try of the statement Try…Catch…Finally. But it is not permitted in blocks of the types Catch and Finally.

Examples

TODO

See also