Man if

From LSWiki

Revision as of 12:08, 11 June 2007; Laine (Talk | contribs)
(diff) ←Older revision | Current revision | Newer revision→ (diff)
Jump to: navigation, search

Synopsis

       if (expr1) statement1;
       else if (expr2) statement2;
       ...
       else if (exprN) statementN;
       else statementX;

Description

The if() statement implements the conditional execution of statements. The expressions 'expr1' .. 'exprN' are evaluate in the order they appear until one of the expressions returns non-0 ('true'). At that point, the statement associated with the expression is executed, and the program continues after the if() statement. If none of the expressions evaluate to 'true', the statementX in the 'else'-branch is executed.

Both the 'else if' branches and the 'else' branch are optional, and there can be any number of 'else if' branches - but there must be one 'if' branch, and the branches must be in the order given above.

Any 'else' or 'else if' always relates to the immediately preceeding 'if' resp. 'else if' conditional. This means that

         if (a)
         if (b) do_b;
         else do_c;

is interpreted as

         if (a) {
           if (b) do_b;
           else   do_c;
         }

See Also

for(LPC), foreach(LPC), do-while(LPC), while(LPC), switch(LPC)

Personal tools