MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | NAME |
| 2 | if |
| 3 | |
| 4 | SYNTAX |
| 5 | if (expr1) statement1; |
| 6 | else if (expr2) statement2; |
| 7 | ... |
| 8 | else if (exprN) statementN; |
| 9 | else statementX; |
| 10 | |
| 11 | DESCRIPTION |
| 12 | The if() statement implements the conditional execution of statements. |
| 13 | The expressions 'expr1' .. 'exprN' are evaluate in the order they |
| 14 | appear until one of the expressions returns non-0 ('true'). At that |
| 15 | point, the statement associated with the expression is executed, and |
| 16 | the program continues after the if() statement. If none of the |
| 17 | expressions evaluate to 'true', the statementX in the 'else'-branch |
| 18 | is executed. |
| 19 | |
| 20 | Both the 'else if' branches and the 'else' branch are optional, and |
| 21 | there can be any number of 'else if' branches - but there must be one |
| 22 | 'if' branch, and the branches must be in the order given above. |
| 23 | |
| 24 | Any 'else' or 'else if' always relates to the immediately preceeding |
| 25 | 'if' resp. 'else if' conditional. This means that |
| 26 | |
| 27 | if (a) |
| 28 | if (b) do_b; |
| 29 | else do_c; |
| 30 | |
| 31 | is interpreted as |
| 32 | |
| 33 | if (a) { |
| 34 | if (b) do_b; |
| 35 | else do_c; |
| 36 | } |
| 37 | |
| 38 | SEE ALSO |
| 39 | for(LPC), foreach(LPC), do-while(LPC), while(LPC), switch(LPC) |