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

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.3k views
Welcome To Ask or Share your Answers For Others

1 Answer

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...