The Label Statement


Statements may be labelled. The switch statement uses constant expressions to label statements with case labels. A statement labelled with an identifier can be the target of a goto statement.

Syntax

labelled_statement:
        identifier: statement
        case constant_expression: statement
        default : statement

Notes

The scope of a label identifier is the function in which it is declared and a label identifier cannot be duplicated within that scope. Label identifiers can be forward referenced; that is, they can occur as the target of a goto statement that precedes the label declaration. Labels have their own name space which does not intersect with the name space of other identifiers; hence, an identifier can be declared with the same name as a label without conflict.

The only use to which a label identifier can be put is to be the target of a goto statement. Case labels and the default label must occur within the body of a switch statement.