| | |
Lost Again...Step Increment
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
![]() |
pascal Syntax (Toggle Plain Text)
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.
Last edited by FlamingClaw; Mar 1st, 2009 at 5:20 am.
I think you're right,the or the can be the right way,'cause these statements are used for that....the point is yours...
With respect FlamingClaw
PASCAL Syntax (Toggle Plain Text)
While..Do
pascal Syntax (Toggle Plain Text)
Repeat..Until
With respect FlamingClaw
Last edited by FlamingClaw; Mar 2nd, 2009 at 2:32 am.
Ok,I know that this thread is not fresh but I have an idea,and working! 

pascal Syntax (Toggle Plain Text)
{ 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=- }
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
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.
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.
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
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
![]() |
Similar Threads
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Please express it to me.
- Next Thread: Pascal code doesnt work and i work out why
Views: 2133 | Replies: 9
| Thread Tools | Search this Thread |
Tag cloud for Pascal and Delphi






