943,589 Members | Top Members by Rank

Ad:
Feb 9th, 2009
0

Lost Again...Step Increment

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gh0sts416 is offline Offline
5 posts
since May 2008
Feb 9th, 2009
0

Re: Lost Again...Step Increment

I Got It Figured Out

But Any Feed Back Would Still Be Appreciated.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gh0sts416 is offline Offline
5 posts
since May 2008
Feb 9th, 2009
0

Re: Lost Again...Step Increment

Step is something that delphi kinda overlooked.

Easiest answer is a while loop.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Mar 1st, 2009
0

Re: Lost Again...Step Increment

pascal Syntax (Toggle Plain Text)
  1. Program increment_for;
  2. Uses Crt;
  3. Var i:Byte;
  4.  
  5. Begin
  6. ClrScr;
  7. For i:=0 To 100 Do
  8. Begin
  9. If i>=100 Then Break;
  10. Inc(i,20); {increment i with 20}
  11. Write(i, ' ');
  12. Dec(i); {decrement i with 1}
  13. End;
  14.  
  15. Repeat
  16. Until KeyPressed;
  17. 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
Last edited by FlamingClaw; Mar 1st, 2009 at 5:20 am.
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Mar 1st, 2009
0

Re: Lost Again...Step Increment

most languages dont like you messing with the itterator. You would do better to use a while loop.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Mar 2nd, 2009
0

Re: Lost Again...Step Increment

I think you're right,the
PASCAL Syntax (Toggle Plain Text)
  1. While..Do
or the
pascal Syntax (Toggle Plain Text)
  1. Repeat..Until
can be the right way,'cause these statements are used for that....the point is yours...
With respect FlamingClaw
Last edited by FlamingClaw; Mar 2nd, 2009 at 2:32 am.
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Mar 29th, 2009
0

Re: Lost Again...Step Increment

Ok,I know that this thread is not fresh but I have an idea,and working!
pascal Syntax (Toggle Plain Text)
  1. {
  2. Question
  3. Increment for loop
  4. }
  5. Program Program01;
  6.  
  7. var i:Byte;
  8.  
  9. Begin {main}
  10. For i:=1 To 100 Do
  11. Begin
  12. i:=i+9; {will step 10}
  13. Write(i,' ');
  14. End;
  15. ReadLn;
  16. End.
  17.  
  18. {
  19. -= Note By FlamingClaw =-
  20.  
  21. All programs created by me are written and tested
  22. in Dev Pascal and/or Turbo Pascal 7.0
  23.  
  24. -= Created By FlamingClaw =-
  25. -=2009.03.29=-
  26. }
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Mar 30th, 2009
0

Re: Lost Again...Step Increment

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.
Last edited by jsosnowski; Mar 30th, 2009 at 10:08 am.
Reputation Points: 11
Solved Threads: 11
Junior Poster in Training
jsosnowski is offline Offline
68 posts
since Nov 2007
Mar 30th, 2009
0

Re: Lost Again...Step Increment

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
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Mar 30th, 2009
0

Re: Lost Again...Step Increment

FlamingClaw,

My bad, you are right.

However, overiding the automatic increment still looks like a bad practice.
Last edited by jsosnowski; Mar 30th, 2009 at 12:47 pm.
Reputation Points: 11
Solved Threads: 11
Junior Poster in Training
jsosnowski is offline Offline
68 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: Please express it to me.
Next Thread in Pascal and Delphi Forum Timeline: Pascal code doesnt work and i work out why





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC