Are you asking for an explanation of the for-loop? The comment above it
explains what it does. The general form is
for (a; b; c)
{
d;
...
}
and it is basically equivalent to the following while-loop:
a;
while (b)
{
d;
...
c;
}
The 'a' part is typically an assignment statement to initialize a "loop
variable" like an integer i that starts out at 0 and increments to 1, 2, 3, etc.
The 'b' part is typically a conditional expression evaluating to true or false,
telling the loop whether to keep going or not. ("Have I reached the end of the
collection yet?")
The 'c' part is typically an expression like i++ to increment the loop variable
for the next pass.
Gordon Smith
Adobe Flex SDK Team
From: [email protected] [mailto:[email protected]] On Behalf
Of Ballai Tibi
Sent: Friday, December 04, 2009 10:48 AM
To: [email protected]
Subject: [flexcoders] am a newbie , can somebody explains to me this simple For
loop statement?
public function removeItem(item:StoreItem):void {
var i:uint; //declares a local variable i of type uint (unsigned int)
/*initialize i with the value 0;
until i is smaller than the collection's length, execute the code inside
the for loop and increment i by one at the end of each step (i++)
*/
for (i=0; i < _collection.length; i++){
//check if the item in the _collection array at position i is equal to
the item that was passed as an argument
if (_collection [i]==item){
//remove 1 item from the _collection array starting at position i
_collection.splice(i, 1);
//since the item we were looking for was found, there's no need to
continue searching
break;
}
}
}
Tibor.