Let’s continue… haha
See what I did there?
Bleh, okay.
Continue statements
A “continue” statement begins the next iteration of the innermost enclosing “for” loop by advancing control to the end of the loop block. The “for” loop must be within the same function.
ContinueStmt = "continue" [ Label ] .
There’s not a lot necessary to say here. continue
works very much like break
. The scoping rules are essentially the same.
The only differences:
continue
only works in afor
loop. It doesn’t apply toswitch
orselect
statements.- Because it doesn’t apply to
switch
orselect
statements, you only need to use a label with nestedfor
loops. - Rather than terminating the loop, it jumps to the next iteration.
If there is a label, it must be that of an enclosing “for” statement, and that is the one whose execution advances.
RowLoop: for y, row := range rows { for x, data := range row { if data == endOfRow { continue RowLoop } row[x] = data + bias(x, y) } }
Quotes from The Go Programming Language Specification Language version go1.22 (Feb 6, 2024)