I've noticed there was something called "repeat" and "wait() while do" I know they both loop, but what's the difference between these two terms?
repeat until and wait() do difference?
1 answer
repeat and while loops are both do the same thing, and that is loop. However they both have different ways of handling arguments.
##While Loops
while loops continue on as long as their condition is met.
That is why you may see scripts have the following;
while wait() do
end
while true do
end
Since wait() always exists, then that condition is met and is true. Therefore the script will loop until that statement is false. Which of course they will never be.
##Repeat Loops
These are somewhat of an opposite as they loop until their condition is met.
Hence why you might see
repeat until nil
repeat wait() until script.Parent.BrickColor == BrickColor.new('Bright blue')
The script will loop anything between repeat and until until the condition is met. Nil means false so the loop will continue to run. For the second script, the loop will run until the script parent's BrickColor is Bright Blue (or they are under an object that does not have a BrickColor property).
######Hopefully this answered your question. If so, hit the Accept Answer button. If you have any further questions, feel free to leave them in the comments below.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
It is also good to note that a repeat loop will always run atleast once, even if the condition starts off false, as it checks the condition at the bottom of the loop, unlike the while loop.