Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Whats the difference between repeat until and while do?

Asked by 5 months ago
While "condition" do
SCRIPT
end

Repeat
SCRIPT
Until "condition"

Isnt the both of them the same they just have to match a condition and keep looping until it matches it. Could anybody tell me the difference? Please help,

0
There really isn't a difference besides being able to do short repeats like "repeat wait() until blank", I tend to use while loops more because other language like java its simpler. Stephenthefox 89 — 5mo

3 answers

Log in to vote
1
Answered by 5 months ago

in While do if the condition is true it will do it while the condition is true
with until it works a bit different it will do the script until the condition is true

Example: With reapet

Local player = game.Player.LocalPlayer
Local Character
reapet wait()
 if player:FindFirstChild("Character") then 
  Character = player.Character 
 end until Character

With While do

Local player = game.Player.LocalPlayer
Local Character
while Character == nil do
 if player:FindFirstChild("Character") then 
    Character = player.Character 
 end
 wait()--so loop wont break
end

so basically no difference but in some cases you would rather to use while do and in other cases reapet until

Ad
Log in to vote
0
Answered by 5 months ago

Hello! There isn’t really a big deference, but, they are usually used for different purposes. For example, the while true do loop is usually used to keep doing a condition forever. While the repeat until Loop is used to keep doing something until finished. Take for example this:

local sum = 0
repeat 
sum = sum + 2
until sum == 8

Hope it helps.

Log in to vote
0
Answered by 5 months ago

while true do will it forever or until something you put for instance

while script.parent.transparency = 0 do
wait (3)
print ("hello")
end
wait (10)
script.parent.transparency = 1

then the output it should have one hello but (x2) replace the 2 with however many it dose in about 10 seconds it then will make the transparency = to 1 you can see it stops printing hello but you can still do the same thing with repeat just a different format

repeat print ("hello") and wait (1) until script.parent.transparency = 1
wait (10)
script.parent.transparency = 1

so what I'm thinking so far of my scripting experience is that while ____ do is a loop like repeat but repeat is easier to do one thing rather than while true do so if we were to do many things

repeat wait (1) and print ("hello") and script.parent.brickcolor = brickcolor3.random() untill script.parent.parent = starterGui
wait (10)
script.parent.parent = game.starterGui

but while do is

while script.parent.parent = workspace do
wait (1)
print ('hello")
end
wait (10)
script.parent.parent = starterGui

so my concudion is that use repeat for one to 3 things but while is for multible becuase repeat dosent look nice and i think that means somthing becuase if for some reson you wanted to edit it it would be harder to find

Answer this question