while true do --code end
While what is true? What does it need to be true in order to do?
Answers explaining while true do
:
To specifically answer your question - while what is true?
The form of a while
loop is
while (condition) do
Where condition is some expression that is checked to pass or fail ( just like an if
statement).
A simple value which passes as the condition
is true
.
true
is a constant (just like 5
is a constant or "cat"
is a constant) which passes conditions of control structures and the boolean operators.
When the condition is true
, then, since it is (a) constant it unconditionally passes -- it will always pass since the condition is always true (true
).
while true do is an infinite loop, as true is always true. This means it will infinitely repeat the code inside it. Using it without a wait() will cause a crash. The way to break out of it is to use
break
break will break out of any loop. Even if it is under an if statement's scope.