Skip to content

iter: document that calling yield after terminated range loop causes runtime panic #74561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/iter/iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Seq2 represents a sequence of paired values, conventionally key-value
or index-value pairs.

Yield returns true if the iterator should continue with the next
element in the sequence, false if it should stop.
element in the sequence, false if it must stop.

For instance, [maps.Keys] returns an iterator that produces the sequence
of keys of the map m, implemented as follows:
Expand All @@ -51,6 +51,9 @@ Iterator functions are most often called by a [range loop], as in:
}
}

If a [range loop] terminates, e.g. by a break statement, a subsequent call
to yield inside the iterator causes a runtime panic.

# Naming Conventions

Iterator functions and methods are named for the sequence being walked:
Expand Down