Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6780 > unrolled thread

Re: Multiple operations in a "Do" expression

Started byBob Hanlon <hanlonr357@gmail.com>
First post2011-11-27 09:16 +0000
Last post2011-11-27 09:16 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Multiple operations in a "Do" expression Bob Hanlon <hanlonr357@gmail.com> - 2011-11-27 09:16 +0000

#6780 — Re: Multiple operations in a "Do" expression

FromBob Hanlon <hanlonr357@gmail.com>
Date2011-11-27 09:16 +0000
SubjectRe: Multiple operations in a "Do" expression
Message-ID<jasv5t$75s$1@smc.vnet.net>
Use a CompoundExpression

Module[{a = 2},
 Do[
  Print[StringForm["`1` * `2` = `3`",
    idx, a, idx*a]];
  Print[StringForm["`1` x `2` = `3`",
    idx, a, idx + a]],
  {idx, 0, 3}]]

Or use a list of operations

Module[{a = 2},
 Do[Print[
   Column[{
     StringForm["`1` * `2` = `3`",
      idx, a, idx*a],
     StringForm["`1` x `2` = `3`",
      idx, a, idx + a]}]],
  {idx, 0, 3}]]

Or use a more complex expression

Module[{a = 2},
 Do[Print[
   StringForm["`1` * `2` = `3`\n`1` x `2` = `3`",
    idx, a, idx + a]],
  {idx, 0, 3}]]


Bob Hanlon

On Sat, Nov 26, 2011 at 5:07 AM, Mark <big.dog1@att.net> wrote:
> Hello community
> I'm learning Mathematica. The expression below just performs one operation. For instructive purposes, what would be the syntax to perform two or more operations with the counter value of the "Do" expression below such as another calculation.
>
> Thanks in advance.
> Mark
>
> Module[{a},
> a=2;
> Do[Print[idx," x ",a, " = ", idx*a],{idx,0,3}](*Multiply the loop-counter by the variable "a" here and print*)
> ]
>
> 0 x 2 = 0
> 1 x 2 = 2
> 2 x 2 = 4
> 3 x 2 = 6
>

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web