For...Next Step Variable
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by ebs.
Fred,
I don't know if this was requested before, but please make the Step value in a For...Next loop a *variable*, not a constant. I often want to set the step based on other variables, and also be able to "reverse direction" in the loop by using: "StepValue = -StepValue".
Regards,
Eric
Fred,
I don't know if this was requested before, but please make the Step value in a For...Next loop a *variable*, not a constant. I often want to set the step based on other variables, and also be able to "reverse direction" in the loop by using: "StepValue = -StepValue".
Regards,
Eric
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by tinman.
--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + all updates, PB3.50)
Better making it an expression (so you can do e.g. "... Step foo+bar(blah)"Originally posted by ebs
I don't know if this was requested before, but please make the Step value in a For...Next loop a *variable*, not a constant. I often want
--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + all updates, PB3.50)
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- User
- Posts: 22
- Joined: Mon Oct 06, 2003 1:42 am
-
- User
- Posts: 22
- Joined: Mon Oct 06, 2003 1:42 am
I second that! Since C allows you to do it.GPI wrote:But would be a good idea (and i can't imagine, that it is a big problem)Fred wrote:Not implemented for now...
Thanks,
Master Games
System: P4 1.9 GHZ, 1 GB DDR Memory, 80 GB Hard Drive, WinXP Home Edition with Latest Patch, Creative labs Audigy Sound Blaster Platinum Sound Card, Geforce 3 Graphics card with 52.16 drivers
Master Games
System: P4 1.9 GHZ, 1 GB DDR Memory, 80 GB Hard Drive, WinXP Home Edition with Latest Patch, Creative labs Audigy Sound Blaster Platinum Sound Card, Geforce 3 Graphics card with 52.16 drivers
Until Fred implements 'Step' as a variable, you can always do it like this:
Code: Select all
; Example of 'For a=1 To 40 Step b' in PureBasic,
; because you can't use variables for 'Step' yet.
b=2 ; The 'Step' value (normally a constant!).
For a=1 To 40
Debug a ; Do whatever processing on 'a' here.
a+b-1 ; This MUST go directly before 'Next'!
Next
oh, pb, use repeat until or while wend instead! brrr...
; for a = 1 to 40 step b
a = 1
while a+b <= 40
; whatever
a = a+b
wend
or
a=1
repeat
; whatever
a = a+b
until a > 40
; for a = 1 to 40 step b
a = 1
while a+b <= 40
; whatever
a = a+b
wend
or
a=1
repeat
; whatever
a = a+b
until a > 40
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
-
- Enthusiast
- Posts: 537
- Joined: Wed Oct 29, 2003 10:35 am
-
- Enthusiast
- Posts: 423
- Joined: Fri Apr 25, 2003 5:22 pm
- Contact:
Of course the compiler could&should watch for the step-parameter if it is a const or a variable and then compile to the fast loop as always if it is a const or to another loop if it is a variable...
Anyway, I personally don't need step-variables, it would only be a nice gimmick.
Anyway, I personally don't need step-variables, it would only be a nice gimmick.
%1>>1+1*1/1-1!1|1&1<<$1=1