Page 1 of 2
Posted: Mon Jan 27, 2003 11:54 pm
by BackupUser
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
Posted: Tue Jan 28, 2003 1:09 am
by BackupUser
Restored from previous forum. Originally posted by VPureBasic.
Hi ebs,
Why you did not try something like...
For x = A to B step C
...
...
Next x
A = ( your start )
B = ( your limit )
C = ( your step value )
Roger
Posted: Tue Jan 28, 2003 10:11 am
by BackupUser
Restored from previous forum. Originally posted by PB.
> Why you did not try something like...
> For x = A to B step C
Doesn't work. Compiler complains about C not being a constant.
Posted: Tue Jan 28, 2003 12:47 pm
by BackupUser
Restored from previous forum. Originally posted by tinman.
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
Better making it an expression (so you can do e.g. "... Step foo+bar(blah)"
--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + all updates, PB3.50)
Posted: Tue Jan 28, 2003 2:56 pm
by BackupUser
Restored from previous forum. Originally posted by Kendrel.
actually it works if the step variable is a constant or a fixed number... but it would be nice if one could also use a variable.
my 2 cents
kendrel
Posted: Tue Jan 28, 2003 3:01 pm
by BackupUser
Restored from previous forum. Originally posted by fred.
I take good notes.
Fred - AlphaSND
Posted: Tue Nov 18, 2003 5:07 pm
by Master Games
Fred, is this feature in the next version? or can it still be added if it is not?
Posted: Tue Nov 18, 2003 6:35 pm
by Fred
Not implemented for now...
Posted: Tue Nov 18, 2003 8:42 pm
by GPI
Fred wrote:Not implemented for now...
But would be a good idea (and i can't imagine, that it is a big problem)
Posted: Tue Nov 18, 2003 11:27 pm
by Master Games
GPI wrote:Fred wrote:Not implemented for now...
But would be a good idea (and i can't imagine, that it is a big problem)
I second that! Since C allows you to do it.
Posted: Thu Nov 27, 2003 4:22 am
by PB
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
Posted: Thu Nov 27, 2003 3:46 pm
by blueznl
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
Posted: Fri Nov 28, 2003 4:28 am
by PB
> use repeat until or while wend instead
But then it's not a For/Next loop with a variable anymore, is it?
Posted: Fri Nov 28, 2003 12:19 pm
by dontmailme
For - Next works well as it is
While - Wend and repeat - until can do the step.....
Everythings quick !
Why change a winning formula ?
This isn't TrueBasic, or a TRUE Basic, it's a very fast basic !
Why do we need the variable step, if it will slow the loop down ?
Posted: Fri Nov 28, 2003 12:59 pm
by Froggerprogger
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.