note_practical_C_programming chapter 8

Practical C Programming                                     Chapter 8
1. for statement
    for (initial-statement; condition; iteration-statement0
        body-statement;
    this statement is equivalent to
    initial-statement;
    while (condition) {
        body-statement;
        iteration-statement;
    }

2. switch statement
    switch (expression) {
        case constant1:
            statement
            ...
            break;

        case constant2:
            statement
            ...
            /* Fall through */

        default:
            statement
            ...
            break;

        case constant3:
            statement
            ...
            break;
    }
    the switch statement evaluates the value of an expression and branches of one of the case labels.
    Duplicate labels are not allowed, so only on case will be selected.
    The expression must evaluate an integer, character, or enumeration
    The case labels can be in any order and must be constants
    The default label can be put anywhere in the switch.
    When C sees a switch statement, it evaluates the expression and then looks for a matching case label. If none is found, the default label is used. If no default found, the statements does nothing.
    A break statement inside a switch tells computer to continue execution after the switch. If a break statement is not there, execution will continue with the next statement.
    In order to clear up confusion, a case section should always end with a break statement or the comment /* Fall through */

3. switch, break, and continue
    the break statement has two uses. in a switch, break causes the program to go to the end of the switch; in a for or while loop, break causes a loop exit.
    The continue statement is valid only inside a loop. Continue will cause the program to go to the top of the loop.

你可能感兴趣的:(Note,on,C)