break: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - ";[ ]+ " to "; ")
m (Some wiki formatting)
 
(6 intermediate revisions by 2 users not shown)
Line 6: Line 6:
|gr1= Program Flow
|gr1= Program Flow


|descr= Skips all loop interations.
|descr= Skips all loop iterations ([[for]], [[forEach]], [[while]], [[findIf]] etc).


|s1= [[break]]
|s1= [[break]]
Line 12: Line 12:
|r1= [[Nothing]]
|r1= [[Nothing]]


|x1= <code>[[for]] "_i" [[from]] 0 [[to]] 3 [[do]]
|x1= <sqf>
// prints 0, 1 and then exits
for "_i" from 0 to 3 do
{
{
    [[if]] (_i [[a == b|==]] 2) [[then]] {[[break]]};
if (_i == 2) then { break };
    [[systemChat]] [[str]] _i;
systemChat str _i;
};</code>
};
</sqf>
 
|x2= <sqf>
private _moneyHolder = objNull;
{
if ("Money_roll" in items _x) then
{
_moneyHolder = _x;
break;
};
} forEach units group player;
 
if (isNull _moneyHolder) then
{
hint "We have to find this money.";
}
else
{
hint format ["%1 has the money!", name _moneyHolder];
};
</sqf>
 
|x3 = <sqf>
0 spawn
{
private _value = 0;
 
while { _value < 10 } do
{
if (_value == 8) then
{
break; // 8 and 9 will never be printed
};
 
systemChat str _value ;
_value = _value + 1;
};
};
</sqf>


|seealso= [[continueWith]] [[continue]] [[breakWith]] [[breakOut]]
|seealso= [[continueWith]] [[continue]] [[breakWith]] [[breakOut]]
}}
}}

Latest revision as of 12:55, 6 November 2024

Hover & click on the images for description

Description

Description:
Skips all loop iterations (for, forEach, while, findIf etc).
Groups:
Program Flow

Syntax

Syntax:
break
Return Value:
Nothing

Examples

Example 1:
// prints 0, 1 and then exits for "_i" from 0 to 3 do { if (_i == 2) then { break }; systemChat str _i; };
Example 2:
private _moneyHolder = objNull; { if ("Money_roll" in items _x) then { _moneyHolder = _x; break; }; } forEach units group player; if (isNull _moneyHolder) then { hint "We have to find this money."; } else { hint format ["%1 has the money!", name _moneyHolder]; };
Example 3:
0 spawn { private _value = 0; while { _value < 10 } do { if (_value == 8) then { break; // 8 and 9 will never be printed }; systemChat str _value ; _value = _value + 1; }; };

Additional Information

See also:
continueWith continue breakWith breakOut

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