Cold Help System: Programming: ColdC Reference Manual: Language Structure: Statements: Conditional


Conditional statements execute other statements if a test condition evaluates true. There are three types of conditional statements in ColdC:

Because the if statement and the if-else statement are similar, they can sometimes be ambiguous. The following code will produce unexpected results:

if (a)
    if (b) c;
else
    d;

The indentation suggests that the else clause should apply to the first if clause, but in fact it applies to the more recent one. Ambiguities like this can be avoided by using braces to create compound statements out of conditional and looping statements, even if there is only one statement. A less ambiguous way to write the above is:

if (a) {
    if (b)
        c;
} else {  
    d;
}


Simple | Conditional | Error-Handling | Looping Statements


the Cold Dark