Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

delphi - Increment an integer variable in a loop

I have "i" that is an integer variable and I would like to do a loop that increments the "i" from 40000 to 90000 adding 1000 each time. Each Result will appear in a ComboBox.

Example: 40000 - 41000 - 42000 - 43000 - ... - 88000 - 89000 - 90000

My code is the following:

var i:integer;
begin
 for i:= 40000 to 90000 do
  begin
   ComboBox1.AddItem(IntToStr(i), nil); //until here the code works
   Inc(i, 1000);                         
  end;

Do you have any suggestions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The alternative to @AndreasRejbrand's solution is a while loop:

i := 40000;
while i <= 90000 do
begin
  ComboBox1.AddItem(IntToStr(i), nil);
  Inc(i, 1000);
end;

or `repeat':

i := 40000;
repeat
  ComboBox1.AddItem(IntToStr(i), nil);
  Inc(i, 1000);
until i > 90000;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...