proposal: Go 2: extend "continue" to jump to start of function #34144
Labels
FrozenDueToAge
LanguageChange
Suggested changes to the Go language
Proposal
Proposal-FinalCommentPeriod
v2
An incompatible library change
Milestone
continue statement begins the next iteration of the innermost "for" loop at its post statement. The "for" loop must be within the same function. If there is a label, it must be that of an enclosing "for" statement, and that is the one whose execution advances.
In addition to the above officially specified definition of continue keyword, I am proposing to extend its definition to also include the containing function body as the outer-most layer. That means:
I occasionally find myself using
for {}
or labels/gotos for an entire function, so I thought this would be a harmless and useful addition to Go. What do you think?Note: When examining this, I realized we can create labels inside functions with the same name. So you can have a label
main:
insidemain()
. So I think it would be better to forbid such label names inside a function if this proposal is accepted.Note 2: Since we have return, we don't need to change anything about "break".
The text was updated successfully, but these errors were encountered: