for do: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
(Redirect to do)
 
Line 1: Line 1:
{{Command|= Comments
#REDIRECT [[do]]
____________________________________________________________________________________________
 
| arma |= Game name
 
|1.00|= Game version
____________________________________________________________________________________________
 
| End of '''for''' command, starts cycle. |= Description
____________________________________________________________________________________________
 
| forCommand '''do''' code |= Syntax
 
|p1= forCommand: [[For Type]] |= Parameter 1
 
|p2= code: [[Code]] |= Parameter 2
 
| [[Anything]] |= Return value
____________________________________________________________________________________________
|x1 =  <code>[[for]] "_x" [[from]] 20 [[to]] 10 [[step]] -2 '''do''' {..code..} </code>
 
 
| [[Control Structures]], [[for forspec]], [[while]] |= See also
 
}}
 
<h3 style="display:none">Notes</h3>
<dl class="command_description">
<!-- Note Section BEGIN -->
 
<!-- Note Section END -->
</dl>
 
[[Category:Scripting Commands|DODSWITCH]]
[[Category:Scripting Commands ArmA|DODSWITCH]]
[[Category:ArmA: Control Structures|DOSWITCH]]
[[Category:Command Group: Program Flow|DOSWITCH]]
 
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on June 4, 2015 - 19:45 (UTC)</dd>
<dt class="note">[[User:Nickorr|Nickorr]]</dt>
<dd class="note">
Dont use this notation if you plan to change the cycle ranges dynamically. The range values are checked only before the cycle started. Use [[for_forspec]] instead. <br/>
 
Example, that won't work correctly:
<code><nowiki>_xy = [1,2,3,4,5,6,7,8,9,10];
for "_i" from 0 to (count _xy - 1) do {
if ( _xy select _i == 3 ) then {
_xy deleteAt _i;
_i = _i - 1;
};
};</nowiki></code>
(Here the <tt><nowiki>_i = 9</nowiki></tt> step will still be checked by the cycle, which will lead to "out of the array range" error.) <br/>
This code will work correctly:
<code><nowiki>_xy = [1,2,3,4,5,6,7,8,9,10];
for [{_i=1},{_i<=(count xy - 1)},{_i=_i+1}] do {
if ( _xy select _i == 3 ) then {
_xy deleteAt _i;
_i = _i - 1;
};
};</nowiki></code>
(The last step here will be <tt><nowiki>_i = 8</nowiki></tt> with array looking like this: <tt><nowiki>[1,2,4,5,6,7,8,9,10]</nowiki></tt>)
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Latest revision as of 21:16, 4 February 2019

Redirect to: