5 Replies Latest reply on Mar 7, 2007 11:41 AM by Newsgroup_User

    Using for loops

    Level 7
      The following loops through all the nodes starting from 0 position:
      total = xmlNode.childNodes.length;
      for (i=0; i<total; i++) {
      image = xmlNode.childNodes.childNodes[0].firstChild.nodeValue;
      description =
      xmlNode.childNodes
      .childNodes[1].firstChild.nodeValue;

      If I change total to total = 3 it loops through the first 3 nodes starting
      from 0 position:

      How can I make it loop for a total of 3 and Start from 4 position?

      Thanks

        • 1. Re: Using for loops
          Level 7
          I meant to ask:
          How can I make it loop for a total of 3 and Start from 2nd position?

          • 2. Re: Using for loops
            bvillanyi Level 1
            Umm - is this a trick question?

            Can't you set the for loop to: for (i=4; i< total, i++) and set total to 7?

            What am I missing?

            Beth
            • 3. Re: Using for loops
              Level 7
              Thanks for your reply.
              Yes that's the first thing I tried but images wont display.
              but images display when for (i=0; i<total; i++) and set total to 7 which
              is what I don't want. Will only go through the first 7 this way.

              "bvillanyi" <webforumsuser@macromedia.com> wrote in message
              news:esn29d$7di$1@forums.macromedia.com...
              > Umm - is this a trick question?
              >
              > Can't you set the for loop to: for (i=4; i< total, i++) and set total to
              > 7?
              >
              > What am I missing?
              >
              > Beth

              • 4. Re: Using for loops
                bvillanyi Level 1
                Based on your second post (which I didn't see until after I posted) then change i to 2 and total to 5. Is there something more complicated that I'm not seeing?

                Beth
                • 5. Re: Using for loops
                  Level 7
                  Yes Beth,
                  I found another variable down in the code which affected "i". It was this
                  variable "p" which was controlling what "i" equals.
                  I missed that one.
                  Thanks for your help.

                  "bvillanyi" <webforumsuser@macromedia.com> wrote in message
                  news:esn3s4$916$1@forums.macromedia.com...
                  > Based on your second post (which I didn't see until after I posted) then
                  > change i to 2 and total to 5. Is there something more complicated that I'm
                  > not seeing?
                  >
                  > Beth