PDA

View Full Version : Types of loops



~alex~
05-02-2007, 03:01 PM
I've noticed in alot of scripts that people tend only to you the repeat .. until() types of loops. I'm making this to let people who don't already know, that there are a good few types of loops you can use, most of which would be more efficient for the job than repeat .. until().

Okay, lets start off with the basic one.

This tutorial requires that you understand variables and procedures


program Loops;
{.include srl/srl.scar}
var
c:integer;
begin
repeat
movemouse(x,y)
c:= c+1
until(c>5)
end.

This one basically repeats Movemouse(x,y) until c is greater than 5... 6 times.

However this loop could have been done other ways too!


program Loops;
{.include srl/srl.scar}
var
c:integer;
begin
while c < 5 do
begin
movemouse(x,y)
c:=c+1
end;
end.

In this example there are two new Keywords:
While and
Do

This loops does movemouse(x,y) while c < 5

Guess what? Theres another one!

program Loops;
{.include srl/srl.scar}
var
i,c:integer;

begin
c:=5
for i:=0 to c do
begin
movemouse(x,y)
i:=1+1
end;
end.

In this one we make a new variable, in this example I've called it 'i'. Then we assign it to 0. Then it will continually do
begin
movemouse(x,y)
i:=1+1
end;

until i = c , which was preset to 5.

Theres one last loop that I'll talk about in the tutorial. If you have a procedure that you want to continually call untill a certain event happens (like a color is found) Scar allows you to call the procedure from within it's self.

program Loops;
{.include srl/srl.scar}

procedure Loop;
begin
if not findcolor(x,y,121113,msx1,msy1,msx2,msy2) then
begin
loop // We call the procedure Loop from within its self.
end;
end;

begin
Loop;
end.

If you have any questions, or if there's any loops I left out just let me know :)

alach11
05-02-2007, 11:11 PM
Cool, I didn't know you could call a procedure from itself.

Gwallunit
05-07-2007, 12:44 PM
Nice tut mate , Will help me out

PwNZoRNooB
05-07-2007, 01:44 PM
Cool, I didn't know you could call a procedure from itself.

Me neither. :confused:

Hugolord
05-07-2007, 01:47 PM
neither did i this really helped TY!

~alex~
05-07-2007, 08:07 PM
Np people :P

Lalaji
05-07-2007, 08:41 PM
I didnt know the very last one you posted on theere...

THank you!!@@