Exiting from Iterators

You can break the execution of an iterator by using either an Exit Function or a Return statement. The following snippet demonstrates how to exit from an iterator function:

Iterator Function StringSeries() As IEnumerable(Of String)    Yield "First string"    Yield "Second string"    Exit Function 'Return is also accepted    Yield "Third string"    '...End Function

Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.