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)
For...Next Step Variable
( 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... )
Re: For...Next Step Variable
gonna bump this thread even if its old..
why 'Step variable' is not implemented?
why 'Step variable' is not implemented?
Signature test: Philippines
Re: For...Next Step Variable
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.
Is there a way around this?
It would be really nice if step could be a variable...
Code: Select all
For i=Random(10, 5) To 0 Step 0
Debug i; will not happen
i-Random(2, 1)
Next
It would be really nice if step could be a variable...
Re: For...Next Step Variable
Code: Select all
For i = 10 To 1 Step -1
i +1 ;undo loop code
i -1 ;anything
Debug i
Next
Re: For...Next Step Variable
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.,:
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.