Page 2 of 2

Posted: Fri Nov 28, 2003 11:02 pm
by blueznl
oh, i think it's something that a decent basic should have, so it's definitely a wish list item, but it's not very important compared with all the other things on my wishlist :-)

hey, it's not important IF other languages have it, only if it makes sense to have it (and for cross language comparisons, and easy porting it's nice to have it)

Posted: Sun Dec 14, 2003 12:01 pm
by Kristel
I think a step-variable is a good idea and I need it
also for my program.

Posted: Tue Dec 23, 2003 8:25 pm
by Andre
@Fred: I hope you put the 'Step variable' on your 'To Do' list. Also users on german forum are requesting this (here)

Re: For...Next Step Variable

Posted: Tue Mar 13, 2018 7:41 pm
by plaxor
gonna bump this thread even if its old..

why 'Step variable' is not implemented?

Re:

Posted: Tue Mar 13, 2018 10:08 pm
by Dude
Fred in 2003 wrote:I take good notes.
It's now 2018. :shock:

Re: Re:

Posted: Sat Dec 14, 2019 10:00 am
by wayne-c
Dude wrote:
Fred in 2003 wrote:I take good notes.
It's now 2018. :shock:
2019, soon 2020 ...

Re: For...Next Step Variable

Posted: Thu Sep 10, 2020 1:35 am
by nsstudios
While the trick with 0 step and manual incrementing/decrementing of the variable works for a positive range, it does not work for the negative.

Code: Select all

For i=Random(10, 5) To 0 Step 0
Debug i; will not happen
i-Random(2, 1)
Next
Is there a way around this?
It would be really nice if step could be a variable...

Re: For...Next Step Variable

Posted: Thu Sep 10, 2020 4:42 am
by Rinzwind

Code: Select all

 For i = 10 To 1 Step -1
  i +1 ;undo loop code
  i -1 ;anything
  Debug i
Next
Looks quite silly, but it works. Apparently the compiler only looks at the Step part, not that the For starts with a higher value and thus is decreasing in each loop.

Re: For...Next Step Variable

Posted: Thu Sep 10, 2020 12:40 pm
by nsstudios
Thanks, but that only works for negative.
If you were to do a -1 step with 1 to 10, that would still not execute, so it looks like I'll have to resort to a manual while loop.
The most recent case where I needed both was with the from, to, and step based on the variable, e.g.,:

Code: Select all

If ddirection=0
step_=1
from_=0
to_=10
Else
step_=direction
from_=current+direction
If direction=-1
to_=0
Else
to_=10
EndIf
EndIf
For i=from_ To to_ Step step_
; from 0 to 10 with step +1 if direction is 0, from current+1 to 10 with step 1 if direction is 1, and current-1 to 0 with step -1 if direction is -1.