A STEP forward into the future.
A STEP forward into the future.
I have requested this before, but never received any reply.
The feature I miss most with PureBasic compared with other basics is the inability for the STEP value in a FOR/NEXT loop to be a variable or expression rather than a constant. It is a real pain that this fundamental core feature is missing and the published workarounds have unwanted side effects in critical cases.
Is there any chance of this feature being incorporated into PB 4.40 which is due in the near future?
The feature I miss most with PureBasic compared with other basics is the inability for the STEP value in a FOR/NEXT loop to be a variable or expression rather than a constant. It is a real pain that this fundamental core feature is missing and the published workarounds have unwanted side effects in critical cases.
Is there any chance of this feature being incorporated into PB 4.40 which is due in the near future?
Anthony Jordan
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
- 1
Use While Wend or Repeat Until, but please, don't slow down the For Next
with Runtime interpretet Step, is useless.
For Next is a speed optimized Integer Counter, nothing else
Use While Wend or Repeat Until, but please, don't slow down the For Next
with Runtime interpretet Step, is useless.
For Next is a speed optimized Integer Counter, nothing else
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
you can Flag the End condition out...akj wrote:But the While condition is dependent on whether the STEP value is positive or negative (this may not be known in advance) and there is no builtin SGN() function in PB so it all starts getting rather messy.
Code: Select all
LoopStart = Random(99)
Repeat
LoopStop = Random(99)
Until LoopStop <> LoopStart
LoopStep = Random(9)+1
If LoopStart > LoopStop
LoopStep = -LoopStep
EndIf
Debug LoopStart
Debug LoopStop
Debug LoopStep
Debug "----------"
LoopCount = LoopStart
Repeat
Debug LoopCount
LoopCount + LoopStep
If LoopStep < 0
If LoopCount < LoopStop
LoopEnd = #True
EndIf
Else
If LoopCount > LoopStop
LoopEnd = #True
EndIf
EndIf
Until LoopEnd
oh... and have a nice day.
+1, if you want to use a constant for speed purposes then use one. this has been standard in the basic languages I've used.
While I rarely want to change a step value mid loop, I often want to call the loop in a function and pass the step value across for that loop iteration. Often the step is a modulo of the loop size to give rows etc.
While I rarely want to change a step value mid loop, I often want to call the loop in a function and pass the step value across for that loop iteration. Often the step is a modulo of the loop size to give rows etc.
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
An excellent example, pdwyer. I wish I could think of something. I know I've run into this before.pdwyer wrote:While I rarely want to change a step value mid loop, I often want to call the loop in a function and pass the step value across for that loop iteration. Often the step is a modulo of the loop size to give rows etc.
+1pdwyer wrote:+1, if you want to use a constant for speed purposes then use one. this has been standard in the basic languages I've used.
While I rarely want to change a step value mid loop, I often want to call the loop in a function and pass the step value across for that loop iteration. Often the step is a modulo of the loop size to give rows etc.