Page 1 of 1

For : Next step

Posted: Sun Jan 24, 2016 3:10 am
by Lunasole
This is more philosophical question ^^, why only constant is allowed to be used as "Step"?
Can there be some special reasons for that (useless) limitation?
"add dword [A], 0x5" might be a bit faster of course than adding , but it doesn't seems to make any difference, especially if both are allowed and related variation of asm-code used.

Code: Select all

Define B = 5
For A = 1 To 10 Step B ; not allowed
	A + 1
Next A
PS. I don't see a big problem with that, While/Repeat can be used easily as alternative, just found it curious.

Re: For : Next step

Posted: Sun Jan 24, 2016 5:43 am
by Keya
Would be nice, i needed it myself not long ago. My workaround was something like this, granted it's not as readable!

Code: Select all

B = 5
Repeat
  A + B   ;A Step B
  Debug(A)
Until A => 10

Re: For : Next step

Posted: Sun Jan 24, 2016 7:09 am
by idle
if you really want the syntax it can be done at the expense of 3 ops

Code: Select all

CompilerIf SizeOf(Integer) = 4 
  Macro rcx : ecx : EndMacro 
CompilerEndIf   

Macro NextStep(var,istep=1)
  EnableASM 
  mov rcx, istep 
  dec rcx 
  add var, rcx
  DisableASM
  Next 
EndMacro 

Define b = 2

For A = 1 To 20 
  Debug A
NextStep(A,b)  

Re: For : Next step

Posted: Sun Jan 24, 2016 10:49 am
by TI-994A
Keya wrote:My workaround was something like this, granted it's not as readable!

Code: Select all

B = 5
Repeat
  A + B   ;A Step B
  Debug(A)
Until A => 10
If we're digressing from your philosophical question into workarounds, then this maintains syntax:

Code: Select all

Define Stepp = 5
For A = 1 To 10 Step 0
  loopCount + 1
  Debug loopCount
  A + Stepp
Next A

Re: For : Next step

Posted: Sun Jan 24, 2016 12:26 pm
by sys64802
Lunasole wrote: Can there be some special reasons for that (useless) limitation?
No, not really. Dartmouth College Basic supported it in 1964 BTW :)

Re: For : Next step

Posted: Sun Jan 24, 2016 11:42 pm
by s0ula55a551n
I found this annoying also and can't see good reason why it has to be constant. Most version of basic I have used allow you to set the step using a variable

Re: For : Next step

Posted: Tue Jan 26, 2016 12:45 pm
by walbus
But, it is very simple for setting the stepping inside any loop....

Re: For : Next step

Posted: Tue Jan 26, 2016 5:37 pm
by s0ula55a551n
Yes you can obviously step the loop counter to a variable. But why not just allow it on the step

Re: For : Next step

Posted: Tue Jan 26, 2016 5:57 pm
by TI-994A
s0ula55a551n wrote:...why not just allow it on the step
In short, Step values in For/Next loops are resolved at compile time, and not at run time.

This is purely a design consideration for improved speed. TTBOMK. :wink:

Re: For : Next step

Posted: Tue Jan 26, 2016 7:46 pm
by sys64802
It's just a limitation. You could have both.
The compiler could add the constant to the loop variable using an immediate operand when a literal constant is specified (like it does now), and add the content of a variable using an intermediate register when a variable is specified instead.
Different code generation, in each case the more appropriate to translate the source code, it's what compilers do.
Obviously one construct can be slower than another, but that happens constantly when programming.
The job of the language should be to be expressive and powerful, the job of the compiler should be to generate the best possible code for the given source, the job of the programmer should be to make the more appropriate choices when putting together the source (and sometimes even sub-optimal choices can still be fixed by the compiler, but that's beyond our world here and it would be excessive to expect that).

Re: For : Next step

Posted: Tue Jan 26, 2016 8:42 pm
by Danilo

Re: For : Next step

Posted: Tue Jan 26, 2016 11:55 pm
by Tenaja
sys64802 wrote:
Lunasole wrote: Can there be some special reasons for that (useless) limitation?
No, not really.
Actually, that is not true. The "special reason" is that 99% of us would rather the dev team worked on more important issues, since this feature can be coded with a Repeat loop. (And besides, there are numerous macros available to implement it using FOR-like syntax, if you search.)

Re: For : Next step

Posted: Tue Jan 26, 2016 11:58 pm
by sys64802
Actually, that's not the reason, there can't be a real reason for that beyond the decision of not doing it at the time. Maybe it was not considered important.
And sure, it's not very important. It's just a nice convenient thing to have.
It's a decision like another, even if in this case we are talking about something minimal, not adding classes.
But I will not insist further, in my opinion there's nothing more to say about something so simple.
The question was "Can there be some special reason" ?
I still think a sensible answer may be "no, not really" and not "to give you more speed" or "to use that time to implement some other feature".
And he already knew the answer, judging by what he wrote.