Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

repeat until and wait() do difference?

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?

1 answer

✓ Accepted 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.

1 comment

2

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.