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

How can you start a loop with a code block?

Asked by 6 years ago

What is the code for starting/ending a loop?

2 answers

Log in to vote
0
Answered by
Galicate 106
6 years ago
number = 1

while true do
wait(1)
number = number + 1
if number == 5 then
    break
end
end
0
Thanks! ProgrammableGami 23 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

There are multiple ways of creating a loop, here are some:

-- Simply every 1 second, 'loop' is printed in the output, this loop is continuous

while true do -- while loop
wait(1) -- waits 1 second
print("loop") -- outputs
end -- ends
-- For loop that counts down from 30, when it hits 0; it ends

Count = 30 -- 30 second

for i = Count, 0, - 1 do -- for loop, loops for 30 seconds
print(i)

-- simple if statement to end the loop when it gets to 10 seconds, you could do this for rounds, etc if you made a game
if i == 10 then
print("round end?")
break -- pretty much destroys the loop / stops the loop
end

end
-- Loops every 1 second, the rest should be pretty self explanatory

while wait(1) do -- while wait() loop
print("hi")
end
0
If you have any problems, let me know. StoleYourClothes 105 — 6y

Answer this question