PEAR Manual
Prev | Chapter 4. Coding Standards | Next

# Control Structures

These include if, for, while, switch, etc. Here is an example if statement, since it is the most complicated of them:

    if ((condition1) || (condition2)) {
        action1;
    } elseif ((condition3) && (condition4)) {
        action2;
    } else {
        defaultaction;
    }

Control statements should have one space between the control keyword and opening parenthesis, to distinguish them from function calls.

You are strongly encouraged to always use curly braces even in situations where they are technically optional. Having them increases readability and decreases the likelihood of logic errors being introduced when new lines are added.

For switch statements:

    switch (condition) {
    case 1:
        action1;
        break;

    case 2:
        action2;
        break;

    default:
        defaultaction;
        break;
    }

Prev | Home | Next
Coding Standards | Up | Function Calls