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

How to do loops? [closed]

Asked by 10 years ago

How do i do loops for scripting?

Locked by TheeDeathCaster and BlueTaslem

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
5
Answered by 10 years ago

Loops? Ok.. Here are some example loops (Sorry if didn't help);

repeat until nil

1.This repeats a loop non-stop (see 3 for more information), but if you want it to stop at a certain point;

repeat wait(0)script.Parent.Value=script.Parent.Value+1 until script.Parent.Value=100

2.For this one, It will repeat until the value equals to 100.

3.But if you take away 'script.Parent.Value=100' to 'nil', then the loop will never stop until something other occurs, like an error.

4.There is also while true do end. Like repeat until nil, but a bit different. Here is an example of a while true do end loop;

while true do
wait(0)
print("Everything is awesome!")
end

5.It will repeatedly print Everything is awesome! non-stop until script is removed or disabled. :P

6.But there is a way to break the while true do end loop, add break into the while true do end statement, and this'll happen;

while true do
wait(0)
print("Everything is awesome!")
break
end

7.As you'll see, it'll only print Everything is awesome! once, because break breaks a loop, same with for LOL=1,9 do end

8.Surprized you can use for for a loop? Here is an Example of one;

for i=1,9 do
wait(0)
print("Everything is awesome!")
end

9.As you'll see, it'll print Everything is awesome! 9 times, unless there is a break (see 6 and 7 for more information)

I hope this helped!

1
It would help TheAlphaStigma if you would also up his reputation. Gamenew09 180 — 10y
0
How do i do that? iluvmaths1123 198 — 9y
0
`repeat until false` seems more canonical BlueTaslem 18071 — 9y
Ad
Log in to vote
-3
Answered by
Vividex 162
10 years ago
while true do
    --stuff
end