Results 1 to 10 of 10

Thread: Repeat x-times

  1. #1
    Join Date
    Jul 2014
    Posts
    18
    Mentioned
    2 Post(s)
    Quoted
    11 Post(s)

    Default Repeat x-times

    Need a way to repeat a piece of my script for 12 times, then go back to another piece of script and need to repeat again for 12 times.
    So kind of this:

    Repeat;
    stuff;
    stuff;
    Repeat;
    stuff;
    untill 12 times
    untill unlimited times

  2. #2
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Simba Code:
    repeat

     repeat
      stuff();
      inc(i);
     until(i >= 12);

     repeat
      things();
      inc(j);
     until(j >= 12);

    until(false);
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Bad™ before everyone gets laser pistols

  3. #3
    Join Date
    Jul 2014
    Posts
    18
    Mentioned
    2 Post(s)
    Quoted
    11 Post(s)

    Default

    Quote Originally Posted by KeepBotting View Post
    Simba Code:
    repeat

     repeat
      stuff();
      inc(i);
     until(i >= 12);

     repeat
      things();
      inc(j);
     until(j >= 12);

    until(false);
    Thanks for the answer and sorry for my unclear post. I'm looking to also loop that repeat for "infinite" amount of times since its part of the other repeat which repeats for infinite. So in that case I would need to make shitton of variables i,j,k,... which wouldn't be too effective since one variable would only last for 30second ish.

  4. #4
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Quote Originally Posted by Hasselihas View Post
    Thanks for the answer and sorry for my unclear post. I'm looking to also loop that repeat for "infinite" amount of times since its part of the other repeat which repeats for infinite. So in that case I would need to make shitton of variables i,j,k,... which wouldn't be too effective since one variable would only last for 30second ish.
    The code i posted will repeat stuff() for 12 times, and then repeat things() for 12 times, infinitely

    repeat..until(false) is the method for repeating infinitely

    Quote Originally Posted by Hasselihas View Post
    I'm looking to also loop that repeat for "infinite" amount of times since its part of the other repeat which repeats for infinite.
    I don't quite understand this bit, if I'm missing something please elaborate and i'll fix it
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Bad™ before everyone gets laser pistols

  5. #5
    Join Date
    Jul 2014
    Posts
    18
    Mentioned
    2 Post(s)
    Quoted
    11 Post(s)

    Default

    Quote Originally Posted by KeepBotting View Post
    The code i posted will repeat stuff() for 12 times, and then repeat things() for 12 times, infinitely

    repeat..until(false) is the method for repeating infinitely


    I don't quite understand this bit, if I'm missing something please elaborate and i'll fix it
    My bad there. Although the problem with that code is that on the first round it loops the i and j for 12 times but after that since the i and j are already over 12 they only come out once.
    So like if you make the first one type 1 and second one 2 it comes out like this:
    11111111111122222222222212121212121212121212121212 121212

  6. #6
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Quote Originally Posted by Hasselihas View Post
    My bad there. Although the problem with that code is that on the first round it loops the i and j for 12 times but after that since the i and j are already over 12 they only come out once.
    So like if you make the first one type 1 and second one 2 it comes out like this:
    11111111111122222222222212121212121212121212121212 121212
    Simba Code:
    repeat
     i := 0;
     j := 0;

     repeat
      stuff();
      inc(i);
     until(i >= 12);

     repeat
      things();
      inc(j);
     until(j >= 12);

    until(false);

    make sure to declare i and j as global integers
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Bad™ before everyone gets laser pistols

  7. #7
    Join Date
    Jul 2014
    Posts
    18
    Mentioned
    2 Post(s)
    Quoted
    11 Post(s)

    Default

    Setting the var into 0 at the beginning of the repeat was exactly what I was in need for. Thanks alot for your help

  8. #8
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

    Default

    Quote Originally Posted by Hasselihas View Post
    Setting the var into 0 at the beginning of the repeat was exactly what I was in need for. Thanks alot for your help
    or you could use a for loop:

    Simba Code:
    procedure something();
    var
      i: integer;

    begin

      for i := 1 to 12 do
      begin
        writeLn('We have looped ' + toStr(i) + ' times.');
        //stuff
      end;

    end;

  9. #9
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    Quote Originally Posted by The Mayor View Post
    or you could use a for loop:

    Simba Code:
    procedure something();
    var
      i: integer;

    begin

      for i := 1 to 12 do
      begin
        writeLn('We have looped ' + toStr(i) + ' times.');
        //stuff
      end;

    end;
    Lets spice that up some.

    Simba Code:
    var
      i: UInt64;

    begin
      for i := 1000000 to 12000000 with 1000000 do
        writeln(i);
    end.

    Big numbers!!

  10. #10
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

    Default

    Quote Originally Posted by Olly View Post
    Lets spice that up some.

    Simba Code:
    var
      i: UInt64;

    begin
      for i := 1000000 to 12000000 with 1000000 do
        writeln(i);
    end.

    Big numbers!!
    Didn't know you could put a with inside a for to do

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •