exitWith: Difference between revisions
Jump to navigation
Jump to search
(add example to demonstrate "scope" behaviour) |
m (+ Wiki links) |
||
Line 23: | Line 23: | ||
When _x is greater then 5, outputs message and terminates code in current level with value of _x |= Example 1 | When _x is greater then 5, outputs message and terminates code in current level with value of _x |= Example 1 | ||
|x2= <code>for "_j" from 1 to 10 do | |x2= <code>[[for var|for]] "_j" [[from]] 1 [[to]] 10 [[do]] | ||
{ | { | ||
player sideChat format["%1",_j]; | [[player]] [[sideChat]] [[format]] ["%1",_j]; | ||
if (_j<nowiki>=</nowiki><nowiki>=</nowiki>5) exitWith {player sideChat "5 is enough"}; | if (_j<nowiki>=</nowiki><nowiki>=</nowiki>5) [[exitWith]] {[[player]] [[sideChat]] "5 is enough"}; | ||
}; | }; | ||
player sideChat "Complete";</code> | [[player]] [[sideChat]] "Complete";</code> | ||
''Only'' the "for" loop will exit when the exitWith condition has been fulfilled (not the whole script). Execution will continue after the end of the loop (player sideChat "Complete"). | ''Only'' the "for" loop will exit when the exitWith condition has been fulfilled (not the whole script). Execution will continue after the end of the loop (player sideChat "Complete"). | ||
|= Example 2 | |= Example 2 |
Revision as of 13:15, 19 August 2007
Description
- Description:
- If the result of condition is true, code is evaluated, and current block with result of code. It only exits the current scope.
- Groups:
- Uncategorised
Syntax
Examples
- Example 1:
if (_x>5) exitWith {echo "_x is too big"; _x}
When _x is greater then 5, outputs message and terminates code in current level with value of _x- Example 2:
for "_j" from 1 to 10 do { player sideChat format ["%1",_j]; if (_j==5) exitWith {player sideChat "5 is enough"}; }; player sideChat "Complete";
Only the "for" loop will exit when the exitWith condition has been fulfilled (not the whole script). Execution will continue after the end of the loop (player sideChat "Complete").
Additional Information
- See also:
- elseControl Structuresthen
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note