The break, continue, and goto statements
Go supports a group of statements designed specifically to exit abruptly out of a running code block, such as switch and for statement, and transfer control to a different section of the code. All three statements can accept a label identifier that specifies a targeted location in the code where control is to be transferred.
The label identifier
Before diving into the core of this section, it is worthwhile to look at the label used by these statements. Declaring a label in Go requires an identifier followed by a colon, as shown in the following snippet:
DoSearch:
Naming your label is a matter of style. However, one should follow the identifier naming guidelines covered in the previous chapter. A label must be enclosed within a function. The Go compiler will not allow unused labels to dangle in the code. Similar to variables, if a label is declared, it must be referenced in the code.
The break statement
As in other C-like languages, the Go break
statement...