SRL Archive - Help and Support

repeat loop with increasing variable


weaselforce

2006-05-20 16:25:21

I want to make a repeat loop, but inside the repeat loop have an increasing variable. And when that variable gets to 10, reset itself to 0 and print a progress report. I dont exactly know how to go about this…

solemn wishes

2006-05-20 16:29:55

try reading my tut on this, it will show you all you need to know


http://82.92.130.193/forums/showthread.php?t=1287

weaselforce

2006-05-20 17:11:28

while(roflcopter>=10) do
Progress;
roflcopter := 0

I did that, should work right? thanks for the awesome tut. I never even thought to use a while loop :(

phantombmx

2006-05-20 19:58:14

here ya go, this is a little more complex but same concept, just you dont need prog to stay at 0 or between 10..

[PHP]procedure proggytest;
var prevprog:integer;
begin
repeat
prevprog:=prog;
repeat
prog:=prog+1;
wait(1000);
until(prog>=prevprog+10)
progressreport;
prog:=prevprog;
until(false)
end;[/PHP]

Dankness

2006-05-20 20:04:19

this is how i would do it…

[php]

var I : Integer;
begin
repeat
for I := 1 to 10 do
begin
DoThisStuff;
end;
Report;
until ( not ( LoggedIn ));
end.

[/php]

Krazy_Meerkat

2006-05-20 20:07:32

Here's what I would do:
[php]procedure NewProcedure;
var
countingvar : Integer;
begin
repeat
countingvar:= countingvar+1;
wait(1000);
if(countingvar = 10)then
begin
progressreport;
countingvar:= 0;
end;
until(false)
end;[/php]

weaselforce

2006-05-20 21:36:05

Thank you all for your suggestions, i think ill use meerkat's method since its the one i understand :) lol

XxKanexX

2006-05-20 21:41:54

For would be better. It's a bit cleaner.


procedure NameMe;
var i: Integer;
begin
repeat
for i:= 1 to 10 do
Wait(1000);
Report;
until(false);
end;

for i:= 1 to 10 do

This means that the integer will do whatever it's told to do from 1 to 10 times. I've told it to Wait(1000), so it will do this 10 times. :)

WhiteShadow

2006-05-20 22:52:00

From: XxKanexX
For would be better. It's a bit cleaner.


procedure NameMe;
var i: Integer;
begin
repeat
for i:= 1 to 10 do
Wait(1000);
Report;
until(false);
end;


This means that the integer will do whatever it's told to do from 1 to 10 times. I've told it to Wait(1000), so it will do this 10 times. :)



He wanted it to reset to 0, remember?

driger1592

2006-05-20 22:58:09

WhiteShadow, the For..To..Do loop may make it 10 until the next time the loop is called, but the reason for resetting it to zero was for the loop anyway (or so I'm assuming) ;)

XxKanexX

2006-05-20 22:58:47

Well he can change the 1 to a 0 then.. Although that will do it 11 times.