Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

2 comments

0

Wow, didn't even cross my mind to do it that way. Thank!

0

the list is called a table lol

This discussion is preserved as it was. New answers, comments, and votes are closed.