SRL Archive - OSR Help

loops


Smarter Child

2011-06-20 20:10:42

Just curious, if i am running a loop like…


begin
repeat
blah;
if not something then Exit; //break; ?
until(false);
end;


i wanna break the loop, but i want it to start back at repeat again, would i use exit or break, i'm just doing this in theory right now..and i haven't scripted in a loooooooooooong time, forgetting the basics :s

Yago

2011-06-20 20:18:10

You would actually use continue.


if not result then continue;

so it would start from the repeat all over again

Smarter Child

2011-06-20 20:21:25

I cannot believe that I forgot about continue :o…


Dgby714

2011-06-20 21:20:05

From: Smarter Child
I cannot believe that I forgot about continue :o…



lol'd at pic

Rich

2011-06-21 04:56:50

But I think you'd need an else to break from the loop, otherwise it might just sit there.

Daniel

2011-06-21 06:24:52

Couple of examples on the various loops on how to achieve this:

Repeat loop:

var
I: Integer;
...
repeat
Inc(I);

if(condition) then
begin
I := 0;
continue;
end;

I := I + 1;
Until(I = 20);

For Loop:

var
I: Integer;
...
for I := 0 to 100 do
begin
if(condition) then
begin
I := 0;
continue;
end;
end;

While loop:

var
I: Integer;
...
while (I < 20)
begin
Inc(I);

if(condition) then
begin
I := 0;
continue;
end;

I := I + 1;
end;

Smarter Child

2011-06-21 22:53:27

@Daniel - Thanks for the examples, but I believe
if not DoSomething then continue;
fixed my problem :)