Statements are the executable instructions performed by the program. Statements produce values and control program flow. A group of statements enclosed in braces makes up a block. Any valid expression or declaration terminated by a semicolon is considered a statement. The statements that control program flow are described in further HELP frames. See also HELP CC LANGUAGE_TOPICS DECLARATION and HELP CC LANGUAGE_TOPICS PREPROCESSOR.
1 – break
The break statement terminates the immediately enclosing while, do, for, or switch statement. Control passes to the statement following the terminated statement. Syntax: break ;
2 – continue
The continue statement passes control to the test portion of the immediately enclosing while, do, or for statement. Syntax: continue ; In each of the following statements, a continue statement is equivalent to "goto label;": while (expression) { statement ... label: ; } do { statement ... label: ; } while (expression); for (expression; expression; expression) { statement ... label: ; } The continue statement is not intended for switches. A continue statement inside a switch statement inside a loop causes reiteration of the loop.
3 – do
The do statement executes a statement one or more times, as long as a stated condition expression is true. Syntax: do statement while ( expression ) ; The do statement is executed at least once. The expression is evaluated after each execution of the statement. If the expression is not 0, the statement is executed again. The statement following the do statement (the body of the do statement) is not optional; the null statement (a lone semicolon) is provided for specifying a do statement with an empty body.
4 – for
The for statement executes a statement zero or more times, with three specified control expressions. Expression-1 is evaluated only once, before the first iteration; expression-2 is evaluated before every iteration; expression-3 is evaluated after every iteration. The for loop terminates if, on evaluation, expression-2 is 0. Syntax: for ( [expression-1] ; [expression-2] ; [expression-3] ) statement The for statement is equivalent to the following format: expression-1; while ( expression-2 ) { statement expression-3; } You can omit any of the three expressions. If expression-2 is omitted, the while condition is true.
5 – goto
The goto statement transfers control unconditionally to a labeled statement. Syntax: goto identifier ; The identifier must be a label located in the current function. You may use goto to branch into a block, but no initializations are performed on variables declared in the block.
6 – if
The if statement is a conditional statement. It can be written with or without an else clause as follows: if ( expression ) statement if ( expression ) statement else statement In both cases, the expression is evaluated, and if it is not 0, the first statement is executed. If the else clause is included and the expression is 0, the statement following else is executed instead. In a series of if-else clauses, the else matches the most recent else-less if.
7 – Labeled
Any statement can be preceded by a label prefix of the following form: identifier: This declares the identifier as a label. The scope of such a declaration is the current function. Labels are used only as the targets of goto statements.
8 – Null
A null statement is a semicolon: ; The null statement provides a null action -- for example, the body of a for loop that takes no action: for(i=0; i < ARRAYSIZE && x[i] == 5; i++) ;
9 – return
The return statement causes a return from a function, with or without a return value. Syntax: return ; return expression ; The return value is undefined if not specified in a return statement. If an expression is specified in the return statement, it is evaluated and the value is returned to the calling function; the value is converted, if necessary, to the type with which the called function was declared. If a function does not have a return statement, the effect (on reaching the end of the function) is the same as with a return statement that does not specify an expression. Functions declared as void may not contain return statements specifying an expression.
10 – switch
The switch statement executes one or more of a series of cases, based on the value of an integer expression. Syntax: switch ( expression ) body The switch's body typically is a block, within which any statement can be prefixed with one or more case labels as follows: case constant-expression : At most one statement in the body may have the label as follows: default : The switch expression is evaluated and compared to the cases. If there is a case matching the expression's value, it is executed; if not, the default case is executed. The switch is normally terminated by a break, return, or goto statement in one of the cases. If there is no matching case and no default, the body of the switch statement is skipped.
11 – while
The while statement executes a statement 0 or more times, as long as a stated condition is true. Syntax: while ( expression ) statement The expression is evaluated before each execution, and the statement is executed if the expression is not 0. The statement following the parentheses (the body of the while statement) is not optional; the null statement (a lone semicolon) is provided for specifying a while statement with an empty body.