SRL Archive - OSR Help

Or Loop Condition and Looping


mrlewcc

2013-09-28 14:09:14

So I want to make my Loop repeat until a condition is met or until another condition is met to make it more effective I know how to simply loop until, I am thinking I will need a while loop but I have no idea how to do while loops.

Also inside one of my other loops I need it to keep going so I do this "i := (i + 1);" at the bottom of the repeat but it only needs to do it up to 28 times whereas it keeps repeating over and over and won't stop is there any way of making it once it =28 to start from the beginning however I can't do it as a normal loop since I have it inside of "repeat untilAllPlayersInactive"

Could anyone help me out please or just push me in the right direction.

Thanks :)

Hoodz

2013-09-28 14:25:13

use: inc(variable)

like this


procedure name;
var
yournumber: integer;
begin
repeat
inc(yournumber);
writeln('our number = ' + inttostr(yournumber));
until (yournumber = 28)
end;

do you get it?

mrlewcc

2013-09-28 14:42:12

From: hoodz
use: inc(variable)

like this


procedure name;
var
yournumber: integer;
begin
repeat
inc(yournumber);
writeln('our number = ' + inttostr(yournumber));
until (yournumber = 28)
end;

do you get it?


This will only repeat until it is at 28 though I want it to repeat till 28 then I want it to reset back to 0 and then go back up to 28 again then back to 0 etc

Brandon

2013-09-28 14:47:07

From: mrlewcc
This will only repeat until it is at 28 though I want it to repeat till 28 then I want it to reset back to 0 and then go back up to 28 again then back to 0 etc




var
I: Integer;
begin
while(true) do
begin
if (I = 28) then
I := 0;

writeln('Number is: ', I);
Inc(I);
end;
end;

Hoodz

2013-09-28 15:06:00

From: mrlewcc
This will only repeat until it is at 28 though I want it to repeat till 28 then I want it to reset back to 0 and then go back up to 28 again then back to 0 etc


If its 28 its going to do something (a procedure) the start of the procedure would be: yournumber := 0
So you just call that at the start of a procedure or at the start of your procedure with the count thing.



procedure name;
var
* yournumber: integer;
begin
yournumber := 0
* repeat
* * inc(yournumber);
* * writeln('our number = ' + inttostr(yournumber));
* until (yournumber = 28)
end;

mrlewcc

2013-09-28 15:53:49

From: hoodz
If its 28 its going to do something (a procedure) the start of the procedure would be: yournumber := 0
So you just call that at the start of a procedure or at the start of your procedure with the count thing.



procedure name;
var
* yournumber: integer;
begin
yournumber := 0
* repeat
* * inc(yournumber);
* * writeln('our number = ' + inttostr(yournumber));
* until (yournumber = 28)
end;

Im trying both out now seem to be working good thank you :)


Also do you know how to have two condition loops so it will repeat until this happens or this happens.

Hoodz

2013-09-28 16:16:14

From: mrlewcc
Im trying both out now seem to be working good thank you :)


Also do you know how to have two condition loops so it will repeat until this happens or this happens.


What do you mean? Like this?

until (yournumber = 28) or (not loggedin)

euphemism

2013-09-28 16:26:02

If you stop to think about it, it isn't difficult to have a loop that checks for multiple conditions. To check for one condition you put it next to the keyword until, if you want to check for more than one, put parentheses next to until and put your conditions inside with an or operator between them like so:


repeat

until ((thisCondition) or (ThatCondition));

A while loop is very much like a repeat-until loop, but the condition for looping is checked before the loop is entered:


while ((thisCondition) or (thatCondition)) do
begin

end;

If the condition is met the first time it is checked, the loop is never entered. Thus, if you want to insure the contents of a loop are executed at least once, use a repeat-until, but if you only want the contents of a loop to be executed if and while a condition is not met, use a while loop.