breakWith: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\|game([0-9]) ?= (.+) \|version([0-9]) ?= (.+) " to "|game$1= $2 |version$3= $4 ")
m (Text replacement - "(\|[pr][0-9]+ *= *[^- ]*) *- *V([a-z ])" to "$1 - v$2")
 
(One intermediate revision by the same user not shown)
Line 10: Line 10:
|s1= [[breakWith]] return
|s1= [[breakWith]] return


|p1= return: [[Anything]] - Value to be returned when iterations are skipped
|p1= return: [[Anything]] - value to be returned when iterations are skipped


|r1= [[Anything]]
|r1= [[Anything]]


|x1= This loop will stop once {{ic|_i}} reaches 5; the output will be "0", "1", "2", "3", "4" and finally "END".
|x1= <sqf>
<code>[[systemChat]] [[call]] {
// stops once _i reaches 5 and outputs 0, 1, 2, 3, 4, END
[[for]] "_i" [[from]] 0 [[to]] 10 [[do]] {
systemChat call {
[[if]] (_i == 5) [[then]] { [[breakWith]] "END"; };
for "_i" from 0 to 10 do {
[[systemChat]] [[str]] _i;
if (_i == 5) then { breakWith "END"; };
systemChat str _i;
};
};
};</code>
};
</sqf>


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

Latest revision as of 15:53, 8 November 2023

Hover & click on the images for description

Description

Description:
Skips all loop iterations and immediately returns the given value.
Groups:
Program Flow

Syntax

Syntax:
breakWith return
Parameters:
return: Anything - value to be returned when iterations are skipped
Return Value:
Anything

Examples

Example 1:
// stops once _i reaches 5 and outputs 0, 1, 2, 3, 4, END systemChat call { for "_i" from 0 to 10 do { if (_i == 5) then { breakWith "END"; }; systemChat str _i; }; };

Additional Information

See also:
continueWith break continue 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