Statements are the basic commands that express the behaviour of a C program. All other language constructs exist to help organize statements so that each has a specific meaning at its position in the program. Consequently, statements can only be used in certain places, namely function bodies.
There are several kinds of statement:
- expression statements that perform computations and have side-effects such as printing and file access;
- conditional statements and switch statements that allow one out of several groups of statements to be selected based on the current state of variables;
- iteration statements that permit enclosed statements to be executed multiple times;
- jump statements such as
break,continueandgoto, that are used in conditional and iteration statements; and - block statements that syntactically combine several statements into one.
- statement
goto-labelled-statementswitch-labelled-statementcompound-statementnull-statementexpression-statementselection-statementiteration-statementjump-statement- goto-labelled-statement
identifier : statement- switch-labelled-statement
case constant-expression : statementdefault : statement- compound-statement
-
{ block-item-list }since C99 -
{ declarationsopt statementsopt }until C99 - null-statement
;- expression-statement
expression ;- selection-statement
if ( expression ) statementif ( expression ) statement else statementswitch ( expression ) statement- iteration-statement
while ( expression ) statementdo statement while ( expression ) ;for ( expressionopt ; expressionopt ; expressionopt ) statement-
for ( declaration expressionopt ; expressionopt ) statementsince C99 - jump-statement
goto identifier ;continue ;break ;return expressionopt ;
A label can be attached to any statement,
allowing it to be a target for a goto. Labels formed using
case or default are only
for use with switch.