for forspec: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Never try to tell a decimal number via binary number in a loop; otherwise the loop will be infinite)
(Redirect to for)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Command|= Comments
#REDIRECT [[for]]
____________________________________________________________________________________________
 
| arma |= Game name
 
|1.00|= Game version
____________________________________________________________________________________________
 
| Creates cycle, using C like style. See example.  |= Description
____________________________________________________________________________________________
 
| '''for''' forspec|= Syntax
|p1 = forspec: [[Array]]
| [[For Type]] |= Return value
____________________________________________________________________________________________
|x1 = <code> '''for''' [{_x<nowiki>=</nowiki>1},{_x<<nowiki>=</nowiki>10},{_x<nowiki>=</nowiki>_x+1}] [[do]] {[[debugLog]] _x;}  </code>
|x2 = <code> _a = 0; '''for''' [{},{_a <= 10},{_a = _a + 1}] [[do]] {[[debugLog]] _a;};  </code>
|x3 = <code> '''for''' [{_a = 0; _b = 1},{_a <= 10},{_a = _a + 1; _b = _b + _b}] [[do]] {};  //_a = 11; _b = 2048;</code>
 
| [[Control Structures]], [[for do]] |= See also
 
}}
 
<h3 style="display:none">Notes</h3>
<dl class="command_description">
<!-- Note Section BEGIN -->
<dd class="notedate">Posted on Apr 15, 2014 - 12:54
<dt class="note">'''[[User:ffur2007slx2_5|ffur2007slx2_5]]'''<dd class="note">
*In ArmA3 ver 1.16 Please note the difference between [[for forspec]] and [[for do]], [[for forspec]] detects Boolean in each scope while [[for do]] doesn’t. e.g.
{| class="wikitable sortable"
 
! command
! Structure
! Summary
 
|-
| [[for forspec]]
|
  a= 0; b = true;
  for [{_i = 0},{_i < 10 && b},{_i = _i + 1}] do {
    a = a + 1;
    if (a >= 7) then {b = false}
  }
| loop can be exited via Boolean control, possible workaround can be like [[BIS_fnc_areEqual]]
 
|-
| [[for do]]
|
  a= 0;
  for "_i" from 0 to 10 do {
    a = a + 1;
    if (a >= 7) exitwith {}
  };
| have to be exited via [[exitWith]]
 
|}
<br>
*Never try to tell a decimal number via binary number in a loop; otherwise the loop will be infinite:
<code>
'''for''' [{_a = 0},{_a != 1},{_a = _a + 0.1}] [[do]] {}; //an infinite loop; _a will never be 1 so the scope will always be true.
</code>
Any binary number behind the decimal point is always the sum of 1/2, 1/4, 1/8, 1/16 etc. so decimal number with odd denominator like 1/3 or 1/10 cannot be exactly equal to each other.
<!-- Note Section END -->
</dl>
 
<h3 style="display:none">Bottom Section</h3>
[[Category:Scripting Commands|FORARRAY]]
[[Category:Scripting Commands ArmA|FORARRAY]]
[[Category:Command_Group:_Program_Flow|{{uc:{{PAGENAME}}}}]]

Latest revision as of 21:14, 4 February 2019

Redirect to: