@BlueApples: Your simple example does not properly illustrate where While..Wend will slow down the execution of loops over For..Next.
Using this code:
Local Lowvalue:Int
Local HighValue:Int
Local Multiplier:Int
For Local I:Int = 0 To (GetLowValue() + GetHighValue()) * GetMultiplier()
Print I
Next
Rem
Local I:int = 0
While I <= (GetLowValue() + GetHighValue()) * GetMultiplier()
Print I
I :+ 1
Wend
End Rem
Function GetLowValue()
Return 10
End Function
Function GetHighValue()
Return 1000
End Function
Function GetMultiplier()
Return 5
End Function
Produces this for the For..Next loop
call _bb_GetLowValue
mov ebx,eax
call _bb_GetHighValue
add ebx,eax
call _bb_GetMultiplier
imul ebx,eax
jmp _34
_21:
push esi
call _bbStringFromInt
add esp,4
push eax
call _brl_standardio_Print
add esp,4
_19:
add esi,1
_34:
cmp esi,ebx
jle _21
_20:
mov eax,0
_22:
pop esi
pop ebx
mov esp,ebp
pop ebp
ret
And this for the While..Wend loop
mov esi,0
jmp _19
_21:
push esi
call _bbStringFromInt
add esp,4
push eax
call _brl_standardio_Print
add esp,4
add esi,1
_19:
call _bb_GetLowValue
mov ebx,eax
call _bb_GetHighValue
add ebx,eax
call _bb_GetMultiplier
imul ebx,eax
cmp esi,ebx
jle _21
_20:
mov eax,0
_22:
pop esi
pop ebx
mov esp,ebp
pop ebp
ret
It is conceivable that the return values of function calls would be used as part of the exit test, and that could result in a considerable amount of time difference with the WHile..Wend loop over the For..Next loop.
Now if the Functions are to be only evaluated once, such as it is in the For..Next loop, you could use this:
Local I:Int = 0
Local Temp:Int = (GetLowValue() + GetHighValue()) * GetMultiplier()
While I <= Temp
Print I
I :+ 1
Wend
Which produces this:
mov esi,0
call _bb_GetLowValue
mov ebx,eax
call _bb_GetHighValue
add ebx,eax
call _bb_GetMultiplier
imul ebx,eax
jmp _19
_21:
push esi
call _bbStringFromInt
add esp,4
push eax
call _brl_standardio_Print
add esp,4
add esi,1
_19:
cmp esi,ebx
jle _21
_20:
mov eax,0
_22:
pop esi
pop ebx
mov esp,ebp
pop ebp
ret
Nearly identical to the For..Next loop, but the loop just gets uglier and uglier. Also the more you must implement yourself, the more likely that bugs will creep in. When I first compiled the two examples above, I forgot to include the
I :+ 1 in the While..Wend loop, a problem that would not occur in the For..Next loop.
ETA: The above is compounded when adding the Step value to the equation, which is where I have problems with the implementation of For..Next.