- 1
list in the Julia programming language
hi guys i have a problem. Recently I started to use the Julia programming language and I came across a situation. Is it possible to create a list that stores numbers and add them all up?. I created the list but now I don't know how to add these numbers. https://code.sololearn.com/c5rIiydoIfEY/?ref=app https://code.sololearn.com/c5rIiydoIfEY/?ref=app
2 Réponses
+ 3
You can use a for loop.
Here is an example:
sum = 0
for i in [1,2,3,4]
sum += i
end
println(sum)
Output: 10
+ 1
Dicts, Tuples and Arrays are how Julia does lists. To add numbers you have to write code that iterates through an Array or Tuple. Dict is more for key-value pair.