SRL Archive - OSR Help

Repeat x-times


Hasselihas

2014-07-18 16:44:49

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

KeepBotting

2014-07-18 16:54:10


repeat

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

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

until(false);

Hasselihas

2014-07-18 17:00:36

From: KeepBotting

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.

KeepBotting

2014-07-18 17:03:11

From: Hasselihas
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

From: Hasselihas
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

Hasselihas

2014-07-18 17:17:51

From: KeepBotting
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:
11111111111122222222222212121212121212121212121212121212

KeepBotting

2014-07-18 17:20:19

From: Hasselihas
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:
11111111111122222222222212121212121212121212121212121212

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

Hasselihas

2014-07-18 17:25:02

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

The Mayor

2014-07-18 20:33:18

From: Hasselihas
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:


procedure something();
var
i: integer;

begin

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

end;

Olly

2014-07-18 21:04:43

From: The Mayor
or you could use a for loop:


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.

var
i: UInt64;

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

Big numbers!!

The Mayor

2014-07-18 21:22:14

From: Olly
Lets spice that up some.

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 :)