Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>yes, the loop increment variable is in the scope of the loops parent, not inside the loop itself. This is intentional, for examples like this:</p> <pre><code>public function getPositionOfValue ( value:String ) : int { for ( var i:int = 0; i &lt; someArray; i++ ) { if (someArray[i] == value ) { break; } } return i; } </code></pre> <p>this allows you to access the value of i once the loop is over. There are lots of cases where this is very useful.</p> <p>What you should do in the cases where you have multiple loops inside the same scope is var the i outside of the loops:</p> <pre><code>public function getPositionOfValue ( value:String ) : int { var i:int; for ( i = 0; i &lt; 15; i++ ) { //do something } for ( i = 0; i &lt; 29; i++ ) { //do something else } return i; } </code></pre> <p>then you get rid of your warning. The other thing to consider is to name your loop increment variables something more descriptive.</p> <p>Update: Two other things to consider:</p> <p><s>1) you shouldn't use uints except for things like colors and places where Flex expects a uint. They are slower than int's to use. Source]<a href="http://gskinner.com/blog/archives/2009/04/as3_performance.html" rel="nofollow noreferrer">1</a></s> Update: it looks like this may no longer be the case in newer versions of the flash player: <a href="http://gskinner.com/blog/archives/2009/04/as3_performance.html" rel="nofollow noreferrer">source</a></p> <p>2) when you var a loop increment variable inside of a loop declaration, you want to make sure you set it to the proper initialization value, usually 0. You can get some hard to track down bugs if you dont. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload