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 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  defaultSection ; i ++ )

   {

   trace (  -  + i ) ;

   }

   }

On Mon, Apr 7, 2008 at 10:12 AM, Helmut Granda [EMAIL PROTECTED] 


wrote:

Is there a way to edit the code below to be included into just one  
for

loop and would it actually be faster? On a side note any site/book
recommendations on how to for this kind of odd sequences..

   TIA





--
...helmut
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[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  defaultSection ; i ++ )

{

trace (  -  + i ) ;

}

}

On Mon, Apr 7, 2008 at 10:12 AM, Helmut Granda [EMAIL PROTECTED]
wrote:

 Is there a way to edit the code below to be included into just one for
 loop and would it actually be faster? On a side note any site/book
 recommendations on how to for this kind of odd sequences..

 TIA




-- 
...helmut
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


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 the lower
part, you can do some code abuse ;)

for (var i:Number = defaultSection; i  (maxSection * 2 - defaultSection);
i++) {
  if (i % maxSection = defaultSection) {
trace(higher  + i % maxSection);
  } else {
trace(lower  + i % maxSection);
  }
}


Please correct me if that's not what you want



On Mon, Apr 7, 2008 at 12:13 PM, Helmut Granda [EMAIL PROTECTED]
wrote:

 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  defaultSection ; i ++ )

{

trace (  -  + i ) ;

}

}

 On Mon, Apr 7, 2008 at 10:12 AM, Helmut Granda [EMAIL PROTECTED]
 wrote:

  Is there a way to edit the code below to be included into just one for
  loop and would it actually be faster? On a side note any site/book
  recommendations on how to for this kind of odd sequences..
 
  TIA




 --
 ...helmut
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


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  maxSection; i++) {
  if (i  defaultSection) {
trace(lower  + i);
  } else {
trace(higher  + i);
  }
 }

 If you absolutely want to run the higher part before you run the lower
 part, you can do some code abuse ;)

 for (var i:Number = defaultSection; i  (maxSection * 2 - defaultSection);
 i++) {
  if (i % maxSection = defaultSection) {
trace(higher  + i % maxSection);
  } else {
trace(lower  + i % maxSection);
  }
 }


 Please correct me if that's not what you want



 On Mon, Apr 7, 2008 at 12:13 PM, Helmut Granda [EMAIL PROTECTED]
 wrote:

  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  defaultSection ; i ++ )
 
 {
 
 trace (  -  + i ) ;
 
 }
 
 }
 
  On Mon, Apr 7, 2008 at 10:12 AM, Helmut Granda [EMAIL PROTECTED]
  wrote:
 
   Is there a way to edit the code below to be included into just one for
   loop and would it actually be faster? On a side note any site/book
   recommendations on how to for this kind of odd sequences..
  
   TIA
 
 
 
 
  --
  ...helmut
  ___
  Flashcoders mailing list
  Flashcoders@chattyfig.figleaf.com
  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




-- 
...helmut
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


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 (i--)
{
   trace(  -  + i );
   if (defaultSection  maxSection)
   {
   while (j--)
   {
   trace(  -  + j);
   }
   }
}

Helmut Granda wrote:

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  defaultSection ; i ++ )

{

trace (  -  + i ) ;

}

}
  


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


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.
(Actually not forever, since eventually an int will overflow and become
false again...)



On Mon, Apr 7, 2008 at 2:05 PM, Steven Sacks [EMAIL PROTECTED]
wrote:

 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 (i--)
 {
   trace(  -  + i );
   if (defaultSection  maxSection)
   {
   while (j--)
   {
   trace(  -  + j);
   }
   }
 }

 Helmut Granda wrote:

  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  defaultSection ; i ++ )
 
 {
 
 trace (  -  + i ) ;
 
 }
 
 }
 
 

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


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--)
   {
   trace( j =  + j);
   }
   }
}

However, somebody managed to suss out what Helmut was really trying to 
achieve.  Their second example, however, was the exact opposite of what 
Helmut wanted, which was an efficient loop.


Doing any kind of math or function call in the comparison function of a 
loop is the polar opposite of efficiency.  ;)

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


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 (according to flasm):

var defaultSection:Number = 3;
var maxSection:Number = 6;
var i:Number = maxSection + 1;

while(--i) {
  if (i  defaultSection) {
trace(lower  + i);
  } else {
trace(higher  + i);
  }
}

This, of course, supposing he doesn't care about the order of execution.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders