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

While true do help?

Asked by
iLegitus 130
9 years ago

So i know while true does,Heres an example

while true do
wait()
print("Hi Mom")
end

But what if i want it to repeat itself? Like re-start. I know theres the "break",Is there something similiar but "repeat"?

3
The code you have should repeat printing 'Hi mom'. Elaborate on what you're asking please. Goulstem 8144 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

edit: Was wrong. Edited the answer to fit better. It seems that I was incorrect, many apologies.If you read the comments, wait() holds the wait for the smallest time interval. This should repeat it correctly. As for breaking a while true do loop, simply type break whenever you wish inside of it, and it will stop it. The most practical use for break is when you are doing a conditional branch where you have different If statements and different loops for each one of them. For restarting a loop, the break command will come into use. What you would do is use If statements and breaks. (There are many alternatives, but this would be the simplest way, I believe.)

Here is an example.

while true do
wait()
print 'Hi mom!'
canchange = false
--here you can either have an outside force change the variable, or already have it set to true and have waits to time it.
    if canchange = true then
    break
        while true do
        print 'Hi dad!'
    end
end
0
It will repeat, and wait() is perfectly valid - wait() will suspend for the smallest interval possible which, in most cases, is 1/30th of a second. duckwit 1404 — 9y
0
wait() waits for 1/30th of a second, duckwit is right... why is this the chosen answer? FutureWebsiteOwner 270 — 9y
0
Perhaps due to the way I answered his question about Break. penguinProgrammer 5 — 9y
0
I edited my answer to be correct... Many apologies. e_e penguinProgrammer 5 — 9y
Ad

Answer this question