Message Boards Message Boards

2 Replies
0 Total Likes
View groups...
Share this post:

DO loop into a list

Posted 10 years ago


i have a structure, which is of a form

Do[Module[{parameters initiation.....}, 
x=some function with respect to g]; 
 Print[x], {g, {1, 2,3,4,5}}]

The above gives sequentially the solution in scalar values.

Instead, i would like to have the result (incrementally) in a list. How can this happen?

Thank you in advance

POSTED BY: nikos miridakis
2 Replies

You might want to look at the functions Sow/Reap or alternatively AppendTo.

Cheers, M.

POSTED BY: Marco Thiel

Let's say that your function is f[g] then

Map[f, Range[5]]

would give you want you want in your particular case

 {f[1], f[2], f[3], f[4], f[5]}
POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract