Anonymous user
Sum and product of an array: Difference between revisions
m
→{{header|Scala}}: product must be mutable
(→{{header|Scala}}: ++ sather) |
m (→{{header|Scala}}: product must be mutable) |
||
Line 856:
// (_ * _) is a shortcut for {(x,y) => x * y}</lang>
It may also be done in a classic imperative way :
<lang scala>var sum = 0;
for (val x <- a) sum = sum + x
for (val x <- a) product = product * x</lang>
|