CONTROL FLOW

For loop

for(;;) {}

The keyword is used to describe a loop that is controlled by a counter. The parentheses enclose three expressions that initialize, check and update the variable used as counter. The body defined by curly braces encloses the statements that are executed at each pass of the loop.

for(int i = 0; i <= 99; i++) { aFunction(); }

The execution of a single pass or the whole loop can be aborted by using a continue or a break statement respectively.

While loop

while() {}

The keyword is used to describe a loop that is controlled by a condition. The parentheses enclose the expression that defines the condition. The body defined by curly braces encloses the statements that are executed at each pass of the loop.

while(i <= 99) { aFunction(); }

The execution of a single pass or the whole loop can be aborted by using a continue or a break statement respectively.

Do-while loop

do {} while();

The keywords are used to describe a loop that is controlled by a condition. The body defined by curly braces encloses the statements that are executed at each pass of the loop. The parentheses enclose the expression that defines the condition.

do { aFunction(); } while(i <= 99);

The execution of a single pass or the whole loop can be aborted by using a continue or a break statement respectively.

In contrast to a simple while loop the body is always executed at least one time even if the expression evaluates to false from the beginning.

Abort a single pass of a loop

continue;

The keyword is used inside the body of a loop to abort a single pass of the loop. All statements in the body after the continue statement are ignored and the next iteration of the loop is executed immediately.

Abort a loop

break;

The keyword is used inside the body of a loop to abort the whole loop. All statements in the body after the break statement are ignored and the loop is exited without executing any further iteration.

If statement

if() {}

The keyword is used to describe the conditional execution of a statement. The parentheses enclose the expression that defines the condition. The curly braces enclose the statements that are executed if the condition evaluates as true.

if(i != 0) { aFunction(); }

In contrast to a loop the statements in curly braces are executed only one time or not at all.

Else statement

if() {} else {}

The keyword is used in conjunction with the keyword if to describe the alternative execution of a statement. The parentheses enclose the expression that defines the condition. The curly braces after the if statement enclose the statements that are executed if the condition evaluates as true. The curly braces after the else statement enclose the statements that are executed if the condition evaluates as false.

if(i != 0) { aFunction(); } else { bFunction(); }

Depending on the condition either the statements in the first curly braces or the statements in the second curly braces are executed.

Return statement

return;

The keyword is used to define a proper exit for a function. If the function has the return type void no value is passed back to the caller of the function.

return aValue;

If the function has a non-void return type a parameter of the same type has to be included in the statement. The value is passed back to the caller of the function.