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: inside main(). 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".
Within a loop, continue has a vaguely sensible meaning: continue with the next iteration of the loop. I can't see any way that continue implies that we should jump to start of the current function. A function is not a loop.
It also doesn't seem like something that comes up all that often. In https://blog.golang.org/go2-here-we-come Robert outlined three criteria for language changes. I'm not sure this meets criteria 1: address an important issue for many people.
As you noted, this can already be done using goto and a label. However, I would say that it's better in most cases to refactor the function and split the loop body into a separate function, that returns whether or not a continue is needed as a boolean.
"continue functionName" makes no sense. What you say is some kind of "repeat functionName" that makes no sense either. You can just run your function recursively or use labels.
This doesn't seem to have much, if any, support, so this looks like it'll be a likely decline.
Leaving open for four more weeks for final comments, though.
No final comments.
Most helpful comment
Within a loop,
continuehas a vaguely sensible meaning: continue with the next iteration of the loop. I can't see any way thatcontinueimplies that we should jump to start of the current function. A function is not a loop.It also doesn't seem like something that comes up all that often. In https://blog.golang.org/go2-here-we-come Robert outlined three criteria for language changes. I'm not sure this meets criteria 1: address an important issue for many people.