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.
COMMUNITY QUESTION
Is it possible to add all the values in a list?
1 answer
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Wow, didn't even cross my mind to do it that way. Thank!
the list is called a table lol