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

What is an efficient for loops?

Asked by 10 years ago

Is it this?

a=0
for i=0, 1, .1 do
    a=a+i
end

or this

for i=0, 1 do
    a = a + 1
end

1 answer

Log in to vote
0
Answered by 10 years ago

They both can work the same

if you do a = a + 1 then heres example how it would work

    for i=0, 10 do
    a = a + 1
    end
    -- what this does is it will add a + 1, 10 times

same thing as doing this which i would recommend to use instead (better practice, more efficient)

    for i=0, 10, 1 do
    a = i
    end
    -- what this does is it adds a by 1 to 10 like the last one the reason it has 1 at the end is how much it skips by to get to 10

if it was 2 then the output would be this

2, 4, 6, 8, 10

Ad

Answer this question