Manual:DIL Manual/else()
Jump to navigation
Jump to search
Contents
else()
Instruction. The second branch of an if.
if (condition) statement1 else statement2
else is part of if and can't stand alone. statement2 runs when the condition is false. It can be a single statement, a block in braces, or another if, which makes an else if chain.
Notes
- No
;between a closing brace andelse:if (a) { ... }; else ...is a syntax error atelse. After a single statement the;is fine:if (a) x := 1; else x := 2;. - An
elsebelongs to the nearestifbefore it. Inif (a) if (b) x := 1; else x := 2;theelsegoes withif (b); put the innerifin braces if it should go withif (a).
Example
dilbegin rate_hp(pc : unitptr);
code
{
if (pc.hp > pc.max_hp / 2)
act("$1n looks healthy.", A_ALWAYS, pc, null, null, TO_ROOM);
else if (pc.hp > 0)
act("$1n is wounded.", A_ALWAYS, pc, null, null, TO_ROOM);
else
{
act("$1n is dying.", A_ALWAYS, pc, null, null, TO_ROOM);
act("You are dying.", A_ALWAYS, pc, null, null, TO_CHAR);
}
return;
}
dilend
Tells the room how a character is doing, with an else if chain.