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

repeat until and wait() do difference?

Asked by
yoshi8080 445 Moderation Voter
8 years ago

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

Log in to vote
1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
8 years ago

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.
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. BlackJPI 2658 — 8y
Ad

Answer this question