How long do loops last

So im learning about loops and is wondering how long they last. If you could give good answer it would be very appreciated by I. Than you.

6 Likes

A while

26 Likes

oops accepted answer thought it was reply how to unaccept
im lookin for serious appreciated answers

1 Like

They last until you want them to end, you then have to put your end case logic into syntax. See http://wiki.roblox.com/index.php?title=Loops

2 Likes

To unaccept an answer just press the accept button again.

4 Likes

I chuckled.

1 Like

Interesting hm

1 Like

Huh, wait, what’s going on here? Strange.

Loops will keep going until they are stopped in some way.

A for loop will run until it’s iteration is complete. Ex:

for i=1,10 do
    print(i)
end
print("Done!")

That example would print numbers 1-10 and then print Done! after it’s done.

The same is true for a while-loop.

while true do --Purposely used True instead of Wait(1)
    print("Woo!")
    wait(1)
end

That script would continuously print “Woo!” in the console.

1 Like

Why does my code never end then if it depends on number?

i = 9007199254740990;

while i < 9007199254740993 do – this is the loop
print(i);
i = i + 1;
end;
print([[done]]) – prints done when it’s done

4 Likes

I can’t tell if you’re trolling or just began scripting, but it doesn’t end probably because you set “i” to a very large number, so it takes a while to get there (if the loop even works, since it looks like it might not).

3 Likes

Nope; that loop should certainly run.
The difference between i and the constant it’s compared to is 3 units.

EDIT: Floating point stupidity, nevermind. Manually testing the constants proves successful, but otherwise it seems it’ll just do its own thing.

1 Like

Nevermind, I didn’t read all of it since the number is so big.

@HardCoreDev if I were you I’d just do

local a = 0

repeat
print(a)
a = a + 1
wait()
until a == 3 

print("Done")

He’s trolling
lol

1 Like