954,160 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Lost Again...Step Increment

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 :)

gh0sts416
Newbie Poster
5 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

I Got It Figured Out :)

But Any Feed Back Would Still Be Appreciated.

gh0sts416
Newbie Poster
5 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

Step is something that delphi kinda overlooked.

Easiest answer is a while loop.

LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
 
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

FlamingClaw
Posting Pro
559 posts since Feb 2009
Reputation Points: 132
Solved Threads: 138
 

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

LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
 

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

FlamingClaw
Posting Pro
559 posts since Feb 2009
Reputation Points: 132
Solved Threads: 138
 

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
Posting Pro
559 posts since Feb 2009
Reputation Points: 132
Solved Threads: 138
 

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.

jsosnowski
Junior Poster in Training
68 posts since Nov 2007
Reputation Points: 11
Solved Threads: 11
 

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
Posting Pro
559 posts since Feb 2009
Reputation Points: 132
Solved Threads: 138
 

FlamingClaw,

My bad, you are right.

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

jsosnowski
Junior Poster in Training
68 posts since Nov 2007
Reputation Points: 11
Solved Threads: 11
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You