1
$\begingroup$

Help me please, how I can write two action in the body of the cycle "for"?

For example, if I need to write Print[] and Append[] at each iteration.

$\endgroup$
  • $\begingroup$ try Print[...];Append[...]? (See CompoundExpression in the docs.) $\endgroup$ – kglr Jun 9 '19 at 22:51
  • $\begingroup$ @kglr, thank you! $\endgroup$ – GThompson Jun 9 '19 at 22:52
  • $\begingroup$ @GThompson but also don't use For. It's slower, more work, and buggier than the many, many more powerful alternatives. $\endgroup$ – b3m2a1 Jun 10 '19 at 0:41
1
$\begingroup$

You can use CompoundExpression (;) (expressions separated by ;) in any argument of For:

For[i = 0; a = {}, i < 4, i++, Print[i]; AppendTo[a, i]]

enter image description here

$\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.