1

{1,1,1,-2,1,2} How acn I multiply the elements in the list using loops?

2 Answers2

4

I wouldn't use a loop here, I would go with:

Times @@ {1, 1, 1, -2, 1, 2}

But if you really need a procedural approach use a For loop instead (even if it's probably not a good idea).

Roman
  • 47,322
  • 2
  • 55
  • 121
Fraccalo
  • 6,057
  • 13
  • 28
2
t = 1; Do[t *= elem, {elem, {1, 1, 1, -2, 1, 2}}]
t
{* -4 *)
MelaGo
  • 8,586
  • 1
  • 11
  • 24