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

Is it possible to add all the values in a list?

Asked by 5 years ago

So I have a list of numbers and I was wondering if there was a way to add all the numbers in the list together.

1 answer

Log in to vote
0
Answered by
Drainhp 41
5 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.
local listOfNumbers = {1,2,3,4,5}
local sum = 0

for i, v in pairs(listOfNumbers) do --loop over the list of numbers
    sum = sum + v --add each number to the sum
end

print(sum)
0
Wow, didn't even cross my mind to do it that way. Thank! JJBIoxxer 50 — 5y
0
the list is called a table lol SoftlockedUnderZero 668 — 5y
Ad

Answer this question