Re: [Flashcoders] Re: Two for loops and one if statement into one for loop.

2008-04-07 Thread Sidney de Koning
Normally you get unexpected (or expected, depends on how you look at it) results when having two for loops and using the same iterator, for the outher loop try using i, and the inner loop try using j. See what happends :) Cheers Sidney On Apr 7, 2008, at 5:13 PM, Helmut Granda wrote: oh

[Flashcoders] Re: Two for loops and one if statement into one for loop.

2008-04-07 Thread Helmut Granda
oh yeah forgot the loop: var defaultSection: Number = 3; var maxSection: Number = 6; for (var i : Number = defaultSection ; i maxSection + 1 ; i ++ ) { trace ( - + i ) ; } if (defaultSection maxSection) { for (var i : Number = 1 ; i

Re: [Flashcoders] Re: Two for loops and one if statement into one for loop.

2008-04-07 Thread Wagner Amaral
I suppose you want to act properly if the counter is lower or higher than defaultSection. If so: for (var i:Number = 0; i maxSection; i++) { if (i defaultSection) { trace(lower + i); } else { trace(higher + i); } } If you absolutely want to run the higher part before you run

Re: [Flashcoders] Re: Two for loops and one if statement into one for loop.

2008-04-07 Thread Helmut Granda
Great.. that is what I was after.. some how I couldn't see it into one for loop. Thanks! On Mon, Apr 7, 2008 at 10:59 AM, Wagner Amaral [EMAIL PROTECTED] wrote: I suppose you want to act properly if the counter is lower or higher than defaultSection. If so: for (var i:Number = 0; i

Re: [Flashcoders] Re: Two for loops and one if statement into one for loop.

2008-04-07 Thread Steven Sacks
Your if statement is pointless because defaultSection is ALWAYS less than maxSection because you're not altering either of those variables. That being said, this is much faster: var defaultSection:int = 3; var maxSection:int = 6; var i:int = maxSection + 1; var j:int = defaultSection; while

Re: [Flashcoders] Re: Two for loops and one if statement into one for loop.

2008-04-07 Thread Wagner Amaral
Well Steven, your code would enter into an infinite loop. It would trace the first i, then the if will be true, and it will loop till j is false (reaches zero). Then while(i--) runs again, the if will be true again, and the while(j--) will run forever, since j will start at -1, which is true.

Re: [Flashcoders] Re: Two for loops and one if statement into one for loop.

2008-04-07 Thread Steven Sacks
Right. I should have set j inside in the if statement each time. var defaultSection:int = 3; var maxSection:int = 6; var i:int = maxSection + 1; var j:int; while (i--) { trace( i = + i ); if (defaultSection maxSection) { j = defaultSection; while (j--) {

Re: [Flashcoders] Re: Two for loops and one if statement into one for loop.

2008-04-07 Thread Wagner Amaral
On Mon, Apr 7, 2008 at 2:49 PM, Steven Sacks [EMAIL PROTECTED] wrote: Doing any kind of math or function call in the comparison function of a loop is the polar opposite of efficiency. ;) Very true! I Missed the efficient part of the question, oops! Here's the best I've got so far