do: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
m (Some wiki formatting)
 
(47 intermediate revisions by 15 users not shown)
Line 1: Line 1:
[[Category:Scripting Commands|DO]]
{{RV|type=command
[[Category:Scripting Commands OFP 1.96|DO]]
[[Category:Scripting Commands ArmA|DO]]
[[Category:Armed Assault: Control Flows|DO]]


|game1= ofp
|version1= 1.85


<h2 style="color:#000066">'''''while'' do ''code'''''</h2>
|game2= ofpe
|version2= 1.00


|game3= arma1
|version3= 1.00


'''Operand types:'''
|game4= arma2
|version4= 1.00


'''while:''' [[While Type]]
|game5= arma2oa
|version5= 1.50


'''code:''' [[Code]]
|game6= tkoh
|version6= 1.00


'''Type of returned value:'''
|game7= arma3
|version7= 0.50


[[Nothing]]
|gr1= Program Flow


'''Compatibility:'''
|descr= Executes ''code''. Used as part of a construct, such as [[while]], [[with]], [[for]] and [[switch]]. The ''code'' is always executed in [[missionNamespace]] unless [[do]] is used with [[with]] as an argument.


Added in version '''1.85'''
|s1= construct [[do]] code


'''Description:'''
|p1= construct: [[While Type]] ([[while]]), [[With Type]] ([[with]]), [[For Type]] ([[for]]), [[Switch Type]] ([[switch]])


Repeat '''code''' while condition is [[true]].
|p2= code: [[Code]]


'''Note (Applies to 1.85-1.97):''' Maximum repeat count for loop is 10000.
|r1= [[Anything]]


If condition is still [[true]] after loop was repeated 10000 times, loop is terminated and error message is shown.
|x1= <sqf>
while { b > a } do
{
a = a + 1;
};
</sqf>


|x2= <sqf>
with uiNamespace do
{
MyUIVar = MyUIVar + 5;
};
</sqf>


'''Examples:'''
|x3= <sqf>
for "_i" from 1 to 10 do
{
systemChat str _i;
sleep 0.5;
};
</sqf>


[[while]] {a>b} '''do''' {a=a+1}
|x4= <sqf>
switch (50) do
{
case 25: { hint "25" };
case 50: { hint "50" }; // hints "50"
case 75: { hint "75" };
default { hint "nope" };
};
</sqf>


A more practical example:
|seealso= [[Control Structures]]
 
}}
To repair all the members of a group to such a level that they are all able to stand up:<br>
{[[while]] {[[not]] [[canStand]] _x} [[do]] {_x [[setDammage]] ([[getDammage]] _x) - 0.01}} [[forEach]] units [[group]] ''unitname''

Latest revision as of 15:17, 11 May 2022

Hover & click on the images for description

Description

Description:
Executes code. Used as part of a construct, such as while, with, for and switch. The code is always executed in missionNamespace unless do is used with with as an argument.
Groups:
Program Flow

Syntax

Syntax:
construct do code
Parameters:
construct: While Type (while), With Type (with), For Type (for), Switch Type (switch)
code: Code
Return Value:
Anything

Examples

Example 1:
while { b > a } do { a = a + 1; };
Example 2:
with uiNamespace do { MyUIVar = MyUIVar + 5; };
Example 3:
for "_i" from 1 to 10 do { systemChat str _i; sleep 0.5; };
Example 4:
switch (50) do { case 25: { hint "25" }; case 50: { hint "50" }; // hints "50" case 75: { hint "75" }; default { hint "nope" }; };

Additional Information

See also:
Control Structures

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