Category:If conditions: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
No edit summary
Clarify dangling else-if
Line 3: Line 3:
Example code:
Example code:


[[ifdead]] { [[spawn]] BLOODPOOL [[killit]] }  
[[ifdead]] { [[spawn]] BLOODPOOL [[killit]] }  


If conditions may be used in conjunction with an [[else]].
If conditions may be used in conjunction with an [[else]].
In a cascade of multiple ''if''s followed by an ''else if'', the latter is bound to the '''uppermost''' of the former ''if''s. Thus, the following code
[[redefinequote]] 114 NOPE
[[ifvare]] 0 1 [[ifvare]] 0 0 [[redefinequote]] 114 ONE
[[else]] [[ifvare]] 0 0 [[redefinequote]] 114 TWO
is equivalent to this explicitly-braced one:
[[redefinequote]] 114 NOPE
[[ifvare]] 0 1 { [[ifvare]] 0 0 [[redefinequote]] 114 ONE
}
else [[ifvare]] 0 0 [[redefinequote]] 114 TWO
and NOT this one, as with most procedural programming languages,
[[redefinequote]] 114 NOPE
[[ifvare]] 0 1 [[ifvare]] 0 0 { [[redefinequote]] 114 ONE
}
else [[ifvare]] 0 0 [[redefinequote]] 114 TWO
and quote 114 contains the string 'TWO' after its execution.


[[Category:All commands]]
[[Category:All commands]]

Revision as of 09:11, 17 October 2011

If conditions evaluate the specified statement, and run code based on the returned value of the evaluation. If conditions are boolean (true or false), and may be strung together.

Example code:

ifdead { spawn BLOODPOOL killit } 

If conditions may be used in conjunction with an else.


In a cascade of multiple ifs followed by an else if, the latter is bound to the uppermost of the former ifs. Thus, the following code

redefinequote 114 NOPE
ifvare 0 1 ifvare 0 0 redefinequote 114 ONE
else ifvare 0 0 redefinequote 114 TWO

is equivalent to this explicitly-braced one:

redefinequote 114 NOPE
ifvare 0 1 { ifvare 0 0 redefinequote 114 ONE
}
else ifvare 0 0 redefinequote 114 TWO

and NOT this one, as with most procedural programming languages,

redefinequote 114 NOPE
ifvare 0 1 ifvare 0 0 { redefinequote 114 ONE
}
else ifvare 0 0 redefinequote 114 TWO

and quote 114 contains the string 'TWO' after its execution.