Re: Getting rid of those deprecated Do[] loops?

• To: mathgroup at smc.vnet.net
• Subject: [mg92805] Re: Getting rid of those deprecated Do[] loops?
• From: Albert Retey <awnl at gmx-topmail.de>
• Date: Mon, 13 Oct 2008 07:06:37 -0400 (EDT)
• References: <gcsctj\$8mj\$1@smc.vnet.net>

```AES wrote:
> Trying to think of a "two-variable iterator" approach that will let one
> produce the same results as
>
> data = { };
> Do[
>    Do[
>       data = AppendTo[data, {aa, bb, xx, yy}],
>       {bb, 10, 30, 10}],
>    {aa, 1, 2}];
> Print[data // TableForm];

> without using those universally deprecated (and even worse, nested)
> Do[ ] loops, not to mention the equally deprecated AppendTo[].

I think this is the easiest way to do what you want:

Flatten[Table[{aa, bb, xx, yy}, {aa, 1, 2}, {bb, 10, 30, 10}], 1]

> Somewhat to my surprise, the construction
>
> Table[{aa = kk[[1]];  bb = kk[[2]];  aa, bb, xx, yy},
>           {kk,  {{1, 10},  {1, 20},  {1, 30},  {2, 10},  {2, 20},
> {2,30}}}
>           ] // TableForm
>
> using a two-dimensional iterator iterator variable kk, actually does
> this, though the "iterator list" is obviously a bit messy.
>
> Is the concept of a multi-dimensional iterator variable kk mentioned in
> the M6 documentation anywhere?  (A search on "Iterate" or "iteration"
> brings up 193 hits at 10 per screen.)

most functions that use iterators work with lists as the second part of
iterators since version 6 and that is documented for each of these
functions, at least for Table I have checked that. When used like that,
they will just iterate over the elemnts of that list, which can be lists
as in your case but also any other mathematica expression you want, eg:

Table[Integrate[expr, x], {expr, {x, x^2, x^3, Sin[x], Exp[-x]}}]

hth,

albert

```

• Prev by Date: Re: Executing external notebook
• Next by Date: Re: NumberSigns and Number Formatting
• Previous by thread: Re: Getting rid of those deprecated Do[] loops?
• Next by thread: Re: Getting rid of those deprecated Do[] loops?