For...Next Step Variable

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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)
( 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... )
Kristel
New User
New User
Posts: 1
Joined: Sun Dec 14, 2003 11:47 am

Post by Kristel »

I think a step-variable is a good idea and I need it
also for my program.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2056
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Post by Andre »

@Fred: I hope you put the 'Step variable' on your 'To Do' list. Also users on german forum are requesting this (here)
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
plaxor
New User
New User
Posts: 2
Joined: Sun Mar 04, 2018 11:04 pm

Re: For...Next Step Variable

Post by plaxor »

gonna bump this thread even if its old..

why 'Step variable' is not implemented?
Signature test: Philippines ;)
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re:

Post by Dude »

Fred in 2003 wrote:I take good notes.
It's now 2018. :shock:
wayne-c
Enthusiast
Enthusiast
Posts: 335
Joined: Tue Jun 08, 2004 10:29 am
Location: Zurich, Switzerland

Re: Re:

Post by wayne-c »

Dude wrote:
Fred in 2003 wrote:I take good notes.
It's now 2018. :shock:
2019, soon 2020 ...
As you walk on by, Will you call my name? Or will you walk away?
nsstudios
Enthusiast
Enthusiast
Posts: 274
Joined: Wed Aug 28, 2019 1:01 pm
Location: Serbia
Contact:

Re: For...Next Step Variable

Post 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...
Rinzwind
Enthusiast
Enthusiast
Posts: 636
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: For...Next Step Variable

Post 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.
nsstudios
Enthusiast
Enthusiast
Posts: 274
Joined: Wed Aug 28, 2019 1:01 pm
Location: Serbia
Contact:

Re: For...Next Step Variable

Post 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.
Post Reply