## Section4.7Control Flow

C provides several language constructs to control the program flow. These determine which statements are executed and when they are executed.

### Subsection4.7.1Selection Statements

The if-statement if (C) A else B evaluates the condition C. If its value is unequal to 0, statement A is executed, otherwise B:

Another selection statement is the switch-statement. It evaluates an expression of type int and jumps to different case labels depending on the result:

If the selecting value fits to no provided case label, execution jumps to the default label. It is important to note that after execution jumps to a label, all statements until the end of the switch block are executed. If this behavior is undesired, the switch block can be left earlier with a break; or a return statement.

### Subsection4.7.2Loops

C has three kinds of loops. The do-while-loop do A while (C) executes the statement A and then checks the condition C to determine if the loop needs to be executed again:

Characteristically, the loop body A is always executed at least once, independently of C.

The while-loop while (C) A repeats A as long as the condition c is non-zero when it is checked before an iteration. In contrast to the do-while-loop, A is never executed if C is not satisfied before executing the loop.

The for-loop is an abbreviation of a while-loop to compactly declare iteration variables:

The break-statement can be used to leave the innermost surrounding loop:

The continue-statement jumps directly to the end of the loop body. For do-while and while-loops, this means that the termination condition is checked in the next step, in for-loops the increment portion of the loop is executed first.

### Subsection4.7.3Function Return

The return-statement, as we have seen before, ends the execution of the current function and returns the program flow to the calling function. Unless the function has a void return type, the return-statement requires a return value: