1 Reply Latest reply on Oct 9, 2006 6:55 AM by Newsgroup_User

    help needed with for loop logic?

    BuzzF
      Hi guys

      I'm having real trouble trying to get my head around the logic of a loop.
      basically I want to conduct a for loop where a variable has the value of a function call on its previous iteration. I know how many iterations i need to do.

      here is an example of what i want to do - (without using a for loop)

      variable1 = joesFunction(content);
      variable2 = joesFunction(variable1);
      variable3 = joesFunction(variable2);
      variable4 = joesFunction(variable3);
      and so on...

      I don't know how to make my for loop work!

      i've currently got:
      variable1 = joesFunction(content);
      for (i=1; i<=totalIterations; i++) {
      _root["variable"+i+1] = joesFunction(eval("variable"+i));
      }


      Can anyone point me in the right direction as to how to write a functioning for loop for this?

      Thanks for all your responses, they're helping a lot!


        • 1. Re: help needed with for loop logic?
          Level 7
          Hi!

          I recommend you use array to solve this problem. Here is an example code:

          content = 100;
          totalIterations = 5;

          function joesFunction(num:Number):Number {
          return num*2;
          }

          var myVar:Array = new Array();
          myVar[0] = joesFunction(content);
          for (i=1; i<=totalIterations; i++) {
          myVar = joesFunction(myVar[i-1]);
          }

          trace(myVar);

          /Jensen/

          "BuzzF" <webforumsuser@macromedia.com> wrote in message
          news:egdac0$cg8$1@forums.macromedia.com...
          > Hi guys
          >
          > I'm having real trouble trying to get my head around the logic of a loop.
          > basically I want to conduct a for loop where a variable has the value of a
          > function call on its previous iteration. I know how many iterations i need
          > to
          > do.
          >
          > here is an example of what i want to do - (without using a for loop)
          >
          > variable1 = joesFunction(content);
          > variable2 = joesFunction(variable1);
          > variable3 = joesFunction(variable2);
          > variable4 = joesFunction(variable3);
          > and so on...
          >
          > I don't know how to make my for loop work!
          >
          > i've currently got:
          > variable1 = joesFunction(content);
          > for (i=1; i<=totalIterations; i++) {
          > _root["variable"+i+1] = joesFunction(eval("variable"+i));
          > }
          >
          >
          > Can anyone point me in the right direction as to how to write a
          > functioning
          > for loop for this?
          >
          > Thanks for all your responses, they're helping a lot!
          >
          >
          >
          >