Loops
✏ Beginners Scripting Guide ✏
WHILE LOOP USAGE
local myBool = true
while myBool then -- If myBool is true then the loop is running
-- We insert a task.wait() to wait 1 second here so it doesn't crash the script and studio.
task.wait(1) -- Wait for 1 second before run the loop again.
print('The loop is running')
endFOR LOOPS USAGE
for i = 10, 0, -1 do
task.wait(1) -- Wait for 1 second before run the loop again.
print(i, ' seconds has passed') -- Will print "x seconds has passed"
endLoop through a table
local myTable = {
myString = 'Hello';
myBool = false;
myNumber = 1;
}
for i, v in pairs(myTable) do -- Pairs return both key and value!
print(i, v) -- This will print "myString & Hello, myBool & false, and myNumber & 1"
endOr:
REPEAT LOOP USAGE
BREAK USAGE
CONTINUE USAGE
Last updated