Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

While true do?

Asked by 10 years ago

What is the function of While true do

2 answers

Log in to vote
3
Answered by
duckwit 1404 Moderation Voter
10 years ago

Here's a fairly official looking definition of a while loop in Lua:

http://www.lua.org/pil/4.3.2.html

A while x do loop is used to do exactly that, loop! But x doesn't have to be "true" it can be any boolean expression (i.e. something that is either true or false)

So in the example you gave @hassancan of the while true do loop, because true is always, well, true, the loop will just keep going for ever! (Or until the script itself stops, such as by setting the Disabled property of the script)

Also bear in mind that if you do use an infinite while true do loop you must use a wait() in the body (contents) of the loop or else it will consume all of the available processing power for that server/player and crash.

while true do
wait()
--Do something over and over here!
end

I hope that answers your question!

0
It's also possible to do "while wait() do / end" to condense the code slightly. GoldenPhysics 474 — 10y
Ad
Log in to vote
-1
Answered by 10 years ago

It loops a script.

1
It loops the scope of the while loop, not the script itself. duckwit 1404 — 10y
0
thank you hassancan 0 — 10y

Answer this question