Web Analytics Made Easy -
StatCounter looping... - CodingForum

Announcement

Collapse
No announcement yet.

looping...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • looping...

    i have 50 times of looping with a counter, can i break it to 2 pages to do accumulation. this is an example:

    i have a for loop,

    for ( var i = 0; i < 50; i++) {
    document.write "Number now is :" &i&"<BR>"
    }

    from the above example the result will be listed 50 lines of
    Number now is :1
    Number now is :2
    Number now is :3
    Number now is :4
    Number now is :5
    .
    . until 50 times.
    .
    Number now is :50

    but what i want is
    when the loop run until i=25, it will stop for while and shown a link or button "Continue>>", when user click on it, the loop will continue runs from i=26 until 50? Just like PAUSE the loop then play back the loop. can javascript do that?
    Thanks.
    =====================================================
    From NinjaTurtle
    ++http://ohmygoh.blogspot.com|http://technology.ohmygoh.com++

  • #2
    This any good?

    <html>

    <head>

    <script>

    num = 50; //total length
    brk = 2; //amout of breaks

    part = 0;
    z = num/brk;

    function next() {
    if (part<brk) {
    more = "";
    for ( y=0; y<z; y++) {
    x = y+part*z;
    more += "Number now is :"+x+"<BR>";
    }
    document.body.innerHTML += more;
    part += 1;
    }
    }

    </script>

    </head>

    <body onload="next();">

    <a href="javascript: next();">more</a><br>

    </body>

    </html>

    If you need any changes just ask.

    Comment


    • #3
      its work but...

      but how if i got 1,000 loops? it will take quit long time to process, it until my PC hang. so any solution? some more inside the loop, still hav many sub loop to run.... how?
      Thanks.
      =====================================================
      From NinjaTurtle
      ++http://ohmygoh.blogspot.com|http://technology.ohmygoh.com++

      Comment


      • #4
        How about this?
        Code:
        function ImSoLoopy()  {
           var numOfLoops = 1000;
           var RestPeriod = 25;
        
           for (var i=0 i< numOfLoops; i++) {
              if (i % RestPeriod == 0)  {
                 alert ("I'm resting every" + RestPeriod + "loops\r" +
                           "Press OK when ready to continue");
              }
              document.write "Number is now: " i;
           }
        }  // function ImSoLoopy()
        So what the heck is this?: if (i % RestPeriod == 0)
        It does a division and returns the remainer. If the remainder is zero then "i" is a multiple of "RestPeriod".

        but how if i got 1,000 loops? it will take quit long time to process,
        No. It won't.
        Last edited by RadarBob; Jul 15, 2002, 07:46 PM.

        Comment


        • #5
          i get few error ... 1 is the semicolon, and other e1 i dunno what is the error..>!!??!!
          Thanks.
          =====================================================
          From NinjaTurtle
          ++http://ohmygoh.blogspot.com|http://technology.ohmygoh.com++

          Comment


          • #6
            Originally posted by NinjaTurtle
            i get few error ... 1 is the semicolon, and other e1 i dunno what is the error..>!!??!!
            RadarBob forgot the + sign and parenthesis:

            document.write("Number is now: " + i);
            Glenn
            vBulletin Mods That Rock!

            Comment

            Working...
            X