News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Loops - variable or command?

Started by stevmjon, February 22, 2025, 09:42:41 PM

Previous topic - Next topic

stevmjon

just wondering when using a loop is it best to use variables or commands?

#1 :

For lp = 0 to GetScreenWidth()

#2 :

width = GetScreenWidth()
For lp = 0 to width

i am not sure if the #1 command is read once or is it read each iteration of the loop?
i have always used variables as these are fast access.
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

kevin

#1
Expressions are pre-evaluated into temp variables.

So GetScreenWidth() is only called once to compute the end of the range.



PlayBASIC Code: [Select]
setfps 30

Do
cls

For xlp=0 to _GetScreenWidth()
print xlp
next

sync

loop spacekey()
end


function _GetScreenWidth()
print "Called _GetScreenWidth()"
EndFunction 10