I am still working with lists/arrays and i have a question, i want to add all the items in the list what i mean is if i have an array like so: {3,2,3,1,3}
the output should be 12
how would i do this?
this should workd:
1 | total = 0 |
2 | array = { 3 , 2 , 3 , 1 , 3 } |
3 | for _,n in ipairs (array) do |
4 | total+ = n |
5 | end |
This works for me when i have to get the sum
1 | Add = { 1 , 2 , 3 , 4 } |
2 | local sum = 0 |
3 | table.foreach(Add, function (i, v) |
4 | sum = sum + v |
5 | end ) |
6 | print (sum) |