I Was Just Wondering is Ther Anyway At All
To Reproduce A VB Step Increment in Delphi.

VB Example:
for i = 0 to 100 step 10

Delphi: ???

Any Help Would Be A Blessing

Thanks,
gh0sts :)

Recommended Answers

All 9 Replies

I Got It Figured Out :)

But Any Feed Back Would Still Be Appreciated.

Step is something that delphi kinda overlooked.

Easiest answer is a while loop.

Program increment_for;
Uses Crt;
Var i:Byte;

Begin
 ClrScr;
 For i:=0 To 100 Do
 Begin
  If i>=100 Then Break;
  Inc(i,20);                                   {increment i with 20}
  Write(i, '  ');
  Dec(i);                                       {decrement i with 1}
 End;

Repeat
Until KeyPressed;
End.

In the turbo pascal there is a function called INC(number,increment) and I think that the pascal was the base of the delphi

most languages dont like you messing with the itterator. You would do better to use a while loop.

I think you're right,the

While..Do

or the

Repeat..Until

can be the right way,'cause these statements are used for that....the point is yours...
With respect FlamingClaw

Ok,I know that this thread is not fresh but I have an idea,and working! :)

{
Question
Increment for loop
}
Program Program01;

var i:Byte;

Begin {main}
   For i:=1 To 100 Do
     Begin
       i:=i+9;  {will step 10}
       Write(i,' ');
     End;
   ReadLn;
End.

{
-= Note By FlamingClaw =-

All programs created by me  are written and tested
in Dev Pascal and/or Turbo Pascal 7.0

-= Created By FlamingClaw =-
-=2009.03.29=-
}

FlamingClaw,
Two thoughts on your example:

1.) i := i + 9; // does not increment by 10
2.) Using the For statement could easily lead to an error in a large body of code. Imagine coming back to this a year from with no memery of the logic. You would see the For statement and assume an increment of 1 with the For statement controling the i variable. It would be better to use a With or Repeat statement because you would still seek out the increment line to evaluate the step size.

try it and you'll see that i:=i+9 will every round 10,cause when run this example you will see that every round value of i will increasing by 1....therefor nedd i:=i+9

FlamingClaw,

My bad, you are right.

However, overiding the automatic increment still looks like a bad practice.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.