Sum and product of an array: Difference between revisions

Content added Content deleted
(added swift)
(Add Nimrod)
Line 1,150: Line 1,150:
= 6</lang>
= 6</lang>
(All these notations are equivalent)
(All these notations are equivalent)

=={{header|Nimrod}}==
<lang nimrod>var xs = @[1,2,3,4,5,6]

var sum, product: int

for x in xs:
sum += x
product *= x</lang>

Or functionally:
<lang nimrod>import sequtils

let
xs = @[1,2,3,4,5,6]
sum = xs.foldl(a + b)
product = xs.foldl(a * b)</lang>


=={{header|Objeck}}==
=={{header|Objeck}}==