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.
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:
Naming your label is a matter of style. However, one should follow the identifier naming guidelines covered in the previous chapter. A label must ...