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
,continue
andgoto
, that are used in conditional and iteration statements; and - block statements that syntactically combine several statements into one.
- statement
goto-labelled-statement
switch-labelled-statement
compound-statement
null-statement
expression-statement
selection-statement
iteration-statement
jump-statement
- goto-labelled-statement
identifier : statement
- switch-labelled-statement
case constant-expression : statement
default : statement
- compound-statement
-
{ block-item-list }
since C99 -
{ declarationsopt statementsopt }
until C99 - null-statement
;
- expression-statement
expression ;
- selection-statement
if ( expression ) statement
if ( expression ) statement else statement
switch ( expression ) statement
- iteration-statement
while ( expression ) statement
do statement while ( expression ) ;
for ( expressionopt ; expressionopt ; expressionopt ) statement
-
for ( declaration expressionopt ; expressionopt ) statement
since 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
.