Labels and goto

Labels

Labels are names given to lines of code in order to direct program flow to those lines later on.

A label consists of a name and the : character:

end:   // ← a label

This label gives the name end to the line that it is defined on.

Note: In reality, a label can appear between statements on the same line to name the exact spot that it appears, but this is not a common practice:

anExpression(); end: anotherExpression();

goto

goto directs program flow to the specified label:

Get hands-on with 1400+ tech skills courses.