1
$\begingroup$

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

$\endgroup$
  • 5
    $\begingroup$ The simplest loop would be Fold[Times, {1, 1, 1, -2, 1, 2}] $\endgroup$ – Bob Hanlon Dec 26 '19 at 17:55
4
$\begingroup$

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).

| improve this answer | |
$\endgroup$
1
$\begingroup$
t = 1; Do[t *= elem, {elem, {1, 1, 1, -2, 1, 2}}]
t
{* -4 *)
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.