Code: Select all
For i=10 To 0
Debug i
Next
Code: Select all
For i=10 To 0 Step -1
Debug i
Next
Code: Select all
For i=10 To 0 Autostep 1
Debug i
Next
because often i use:
Code: Select all
for x=y to z
Code: Select all
For i=10 To 0
Debug i
Next
Code: Select all
For i=10 To 0 Step -1
Debug i
Next
Code: Select all
For i=10 To 0 Autostep 1
Debug i
Next
Code: Select all
for x=y to z
Code: Select all
Procedure.l Sgn(in.l)
result.l = 0
IF in <> 0: result.l = in.l/ABS(in.l): EndIf
ProcedureReturn result
EndProcedure
Code: Select all
For x=y To z Step(Sgn(z-y))
Debug Str(i)
Next
In the extreme you could substitute all loops by if and gotoblueznl wrote:i consider for / next to be something simple and quick to create loops, i'd go for while / wend for anything more complex
Code: Select all
' exbasic
for a = 1 to 10
if whatever condition is met :-)
a = 10
endif
next a
Code: Select all
a=0
while a<10
a = a+1
if whatever condition is met :-)
a = 10
endif
wend
Code: Select all
For i=10 To 0 Autostep 1
Debug i
Next
The compiler could automatically check whats the step count, 1 or -1.MLK wrote:nothing happens:its ok so far, but it would be nice to have an option like:Code: Select all
For i=10 To 0 Debug i Next
Code: Select all
For i=10 To 0 Autostep 1 Debug i Next
Code: Select all
If FROM < TO
STEP = 1
Elseif FROM > TO
STEP = -1
; Else
; STEP = 0 ; equal, no step needed
Endif
Code: Select all
If FROM < TO
STEP = Step
Elseif FROM > TO
STEP = -Step
; Else
; STEP = 0 ; equal, no step needed
Endif
I couldn't have summarized it better. A new keyword just for blurring the sign of the step width seems overkill. TOWARDS is a very naturally sounding suggestion, but since AUTOSTEP is immediately preceeding the value it influences, AUTOSTEP wins the direct comparison. I consider DOWNTO the worst alternative for the reason given by GPI .Dare2 wrote:votes for: Step (expression)
And puts in a plug for SGN and NOT