Labels and goto


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 directs program flow to the specified label:

Get hands-on with 1000+ tech skills courses.