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"?
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"?
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
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.
wait() waits for 1/30th of a second, duckwit is right... why is this the chosen answer?
Perhaps due to the way I answered his question about Break.
I edited my answer to be correct... Many apologies. e_e
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
The code you have should repeat printing 'Hi mom'. Elaborate on what you're asking please.