1 | While "condition" do |
2 | SCRIPT |
3 | end |
4 |
5 | Repeat |
6 | SCRIPT |
7 | 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,
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
1 | Local player = game.Player.LocalPlayer |
2 | Local Character |
3 | reapet wait() |
4 | if player:FindFirstChild( "Character" ) then |
5 | Character = player.Character |
6 | end until Character |
With While do
1 | Local player = game.Player.LocalPlayer |
2 | Local Character |
3 | while Character = = nil do |
4 | if player:FindFirstChild( "Character" ) then |
5 | Character = player.Character |
6 | end |
7 | wait() --so loop wont break |
8 | end |
so basically no difference but in some cases you would rather to use while do and in other cases reapet until
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:
1 | local sum = 0 |
2 | repeat |
3 | sum = sum + 2 |
4 | until sum = = 8 |
Hope it helps.
while true do will it forever or until something you put for instance
1 | while script.parent.transparency = 0 do |
2 | wait ( 3 ) |
3 | print ( "hello" ) |
4 | end |
5 | wait ( 10 ) |
6 | 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
1 | repeat print ( "hello" ) and wait ( 1 ) until script.parent.transparency = 1 |
2 | wait ( 10 ) |
3 | 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
1 | repeat wait ( 1 ) and print ( "hello" ) and script.parent.brickcolor = brickcolor 3. random() untill script.parent.parent = starterGui |
2 | wait ( 10 ) |
3 | script.parent.parent = game.starterGui |
but while do is
1 | while script.parent.parent = workspace do |
2 | wait ( 1 ) |
3 | print ('hello") |
4 | end |
5 | wait ( 10 ) |
6 | 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