exitWith: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(More accurate typing (using helper types))
(Scope for exitWith clarified.)
Line 9: Line 9:
| If the result of condition is [[true]], code is evaluated, and current block with result of code. It only exits the current scope.
| If the result of condition is [[true]], code is evaluated, and current block with result of code. It only exits the current scope.


exitWith exits the execution of a context, which doesnt mean it will exit a script.
exitWith exits the execution of a loop defined by one of commands [[do]], [[for]], [[count]] or [[forEach]]. It exits the loop only, not the script. |= Description
A context is defined, for example, by while loops, for loops, if blocks, etc.
To simplify, if you have code between {}, then you have a context. |= Description
____________________________________________________________________________________________
____________________________________________________________________________________________



Revision as of 15:36, 8 August 2008

-wrong parameter ("Arma") defined!-1.00
Hover & click on the images for description

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. exitWith exits the execution of a loop defined by one of commands do, for, count or forEach. It exits the loop only, not the script.
Groups:
Uncategorised

Syntax

Syntax:
if (condition) exitWith {Code}
Parameters:
If Type
Code
Return Value:
Anything

Examples

Example 1:
if (_x>5) exitWith {echo "_x is too big"; _x} When _x is greater than 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

Notes

Bottom Section