Why does the function while true do seem to lag online now?
Is there a more effective substitute?
First, while true do
is not a function. That is a combination of a loop declaration (of the while
type), and a conditional statement (which is what true
is).
Thus, while true do
is nothing more than just the declaration of a while loop that continues until its condition becomes equivalent to false
. Since true
is never false
, your loop will never end.
But that's besides the point.
Loops will never create perceivable latency. Never. They are what is commonly known as a control flow statement, which only redirect the natural flow of code. In the case of loops, if the loop's condition is true then it redirects the flow of the code back to the start of the loop.
What creates latency are the contents.
So let's ignore the loop portion of your code and look at what's remaining... wait()
and print'hello world'
. Your culprit is right there: the print
statement should not be abused and should only be used sparingly because writing to the output is an expensive operation.
This means that it is more likely to take up considerably more computer resources than anything else, and since you're writing to the output literally every single opportunity you can, you shouldn't be surprised that your print
statements are eating up your computer's resources, bit-by-bit.