Labeled statements

There are three kinds of labels: identifier, case, and default.

Read syntax diagramSkip visual syntax diagramLabeled statement syntax
 
>>-identifier--:--statement------------------------------------><
 

The label consists of the identifier and the colon (:) character.

An identifier label may be used as the target of a goto statement. A goto statement can use a label before its definition. Identifier labels have their own namespace; you do not have to worry about identifier labels conflicting with other identifiers. However, you may not re-declare a label within a function.

IBM extension An identifier label may also be used as the target of a #pragma exception_handler directive. See the Websphere Development Studio: ILE C/C++ Programmer’s Guide for examples and more information about using the #pragma exception_handler directive.

Case and default label statements only appear in switch statements. These labels are accessible only within the closest enclosing switch statement.

Read syntax diagramSkip visual syntax diagramcase statement syntax
 
>>-case--constant_expression--:--statement---------------------><
 

Read syntax diagramSkip visual syntax diagramdefault statement syntax
 
>>-default--:--statement---------------------------------------><
 

The following are examples of labels:

 comment_complete : ;            /* null statement label */
 test_for_null : if (NULL == pointer)

Related information



[ Top of Page | Previous Page | Next Page | Contents | Index ]