karlkarlngng
2010-03-06 01:04:31
i got a question i know this might have been posted before but how do i make a loop that loops 10 times then stops etc and if u dont have an answer plz dont crtisize
2010-03-06 01:04:31
2010-03-06 01:12:52
From: karlkarlngng
i got a question i know this might have been posted before but how do i make a loop that loops 10 times then stops etc and if u dont have an answer plz dont crtisize
repeat
//stuff
Inc(I);
until(I >= 10);
for I := 0 to 10 do
begin
//stuff
end;
while(I <= 10) do
begin
//stuff
Inc(I);
end;
2010-03-06 09:37:01
repeat
//stuff
Inc(I);
until(I >= 10);
Use this loop if you know the code in it needs to be run at least once
for I := 0 to 10 do
begin
//stuff
end;
Use this type of loop when you know how many times the code in it will be run (i.e. Your end condition is numberic rather than logical)
while(I <= 10) do
begin
//stuff
Inc(I);
end;
Use this type when the code in the loop does not necessarily need to be run
2010-03-06 11:29:46
program New;
var
I: Integer;
begin
end.Inc(I);Is pretty muchI := I + 1;It is just adding one onto the value of the number. Therefor every time it would go through one of the loops above, it would add the value of one onto the integer I, and when I is equal to 10, it would break out of the loop.2010-03-06 11:36:28
From: bionicle1800
Just want to add a bit and explain some things…
you need to call I as an integer. very simple.program New;
var
I: Integer;
begin
end.
Now I automatically has the value of 0.
The procedureIs pretty muchInc(I);It is just adding one onto the value of the number. Therefor every time it would go through one of the loops above, it would add the value of one onto the integer I, and when I is equal to 10, it would break out of the loop.I := I + 1;
If you need anything else, or don't understand something, don't be afraid to post, no one will criticize :)
IncEx(I, x); //Where x is a numbercomes out asI := I + x; //Where x is a number
2010-03-06 12:17:25
program New;
var i:integer;
begin
i := 0; //starts out as 0 by default, but just in case you use used i before...
repeat
writeln(inttostr(i));
Inc(i);
until i >= 10;
writeln('');
i := 1;
repeat
writeln(inttostr(i));
Inc(i);
until i >= 11;
writeln('');
i := 0;
repeat
writeln(inttostr(i));
Inc(i);
until i > 9;
writeln('');
i := 1;
repeat
writeln(inttostr(i));
Inc(i);
until i > 10;
writeln('');
for i := 0 to 9 do //this makes i start at 0 anyway
begin
writeln(inttostr(i));
end;
writeln('');
for i := 1 to 10 do
begin
writeln(inttostr(i));
end;
writeln('');
i := 0;
while i < 10 do
begin
writeln(inttostr(i));
Inc(i);
end;
writeln('');
i := 0;
while i <= 9 do
begin
writeln(inttostr(i));
Inc(i);
end;
writeln('');
i := 1;
while i < 11 do
begin
writeln(inttostr(i));
Inc(i);
end;
writeln('');
i := 1;
while i <= 10 do
begin
writeln(inttostr(i));
Inc(i);
end;
writeln('');
end.These should all do something 10 times.