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

Whats the difference between repeat until and while do?

Asked by 5 years ago
1While "condition" do
2SCRIPT
3end
4 
5Repeat
6SCRIPT
7Until "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 94 — 5y

3 answers

Log in to vote
1
Answered by 5 years 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

1Local player = game.Player.LocalPlayer
2Local Character
3reapet wait()
4 if player:FindFirstChild("Character") then
5  Character = player.Character
6 end until Character

With While do

1Local player = game.Player.LocalPlayer
2Local Character
3while Character == nil do
4 if player:FindFirstChild("Character") then
5    Character = player.Character
6 end
7 wait()--so loop wont break
8end

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 years 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:

1local sum = 0
2repeat
3sum = sum + 2
4until sum == 8

Hope it helps.

Log in to vote
0
Answered by 5 years ago

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

1while script.parent.transparency = 0 do
2wait (3)
3print ("hello")
4end
5wait (10)
6script.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

1repeat print ("hello") and wait (1) until script.parent.transparency = 1
2wait (10)
3script.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

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

but while do is

1while script.parent.parent = workspace do
2wait (1)
3print ('hello")
4end
5wait (10)
6script.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