Variable after for-step

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Sunny
User
User
Posts: 16
Joined: Wed Feb 04, 2004 7:46 pm
Location: Germany | Hannover

Variable after for-step

Post by Sunny »

Hi,

if it's not already on the to-do-list, it will be nice to have the possibility to have a variable as the "step" of a for-loop. Now it's only possible to make a "for-loop-step" with a constant value, variables are not accepted.

mfg.

Sunny
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

Post by oldefoxx »

I agree. This is particularly true when you want to troll through variible length strings, and use Len() as the termination point.

An interesting problem with Len() is that in some cases, you may modify the string as a result of what you find. For instance, you may squeeze out excessive spaces, or convert Tab (Chr(9)) codes into extended spaces to position the remaining characters properly. This changes the length of the string, but as far as I know, the original termination value is always precalculated by Basic compilers that support it, and the For loop is uneffected by the change in the actual length of the string. This makes for a faster For loop cycle, but becomes one of the reasons why a Repeat Until process is needed in place of a For Next loop.
has-been wanna-be (You may not agree with what I say, but it will make you think).
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

I'd prefer an expression for maximum flexibility. This topic has been requested a few times so I guess Fred knows about it :)
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

It does not answer well, as it does not answer for floats at all but :

for i = 1 to n
; do what you want
i + something
next

works anyway!

.... in the meanwhile
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
Sunny
User
User
Posts: 16
Joined: Wed Feb 04, 2004 7:46 pm
Location: Germany | Hannover

Post by Sunny »

fweil wrote:It does not answer well, as it does not answer for floats at all but :

for i = 1 to n
; do what you want
i + something
next

works anyway!

.... in the meanwhile
But maybe in some later versions, you will not be allowed to change the counter-variable, in this example it's "i". I remember, not long time ago, you could not change the counter-variable in PB.

But thanks for this suggestion, this way I can do what I want to do with a variable step.
Post Reply