Page 1 of 1
Variable after for-step
Posted: Mon May 24, 2004 4:59 pm
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
Posted: Tue May 25, 2004 6:02 pm
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.
Posted: Tue May 25, 2004 7:59 pm
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 :)
Posted: Tue May 25, 2004 8:57 pm
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
Posted: Wed May 26, 2004 12:12 am
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.