# Mathematica: Lists

• Feb 23rd 2010, 07:14 AM
Niles_M
Mathematica: Lists
Hi all

I have the following code:

For[i = 0, i < 98, i++,
q = i*100;
For[j = 102 + q, j < 2*100 + q, j++,
Print[j]]]

The output of this loop I wish to put in a list. Can you guys give me a hint to do that?

Sincerely,
Niles.
• Feb 23rd 2010, 07:50 AM
Niles_M
Ok, I just used Create Lists - Wolfram Mathematica 7 Documentation

Mathematica is well-documented.
• Feb 23rd 2010, 07:53 AM
Nyrox
You can always define a help variable

$res=\{ \}$

and replace $Print[j]$ with $AppendTo[res,j]$. At the end, just ask the program to return $res$.
• Feb 23rd 2010, 08:11 AM
Niles_M
That solution was much nicer than mine; thanks. Do you know if it is possible to perform multiple tasks in an if-condition? I.e.

If[2>1,
Do this
Also do this
Also do this and this,
Else only do this
]

?
• Feb 23rd 2010, 08:22 AM
Nyrox
Of course:

If [ Condition, Action 1; Action 2; Actions 3; ... ; Action n].

Just separate the tasks by ; and keep the , for telling the If what to do should the condition fail to be true.
• Feb 27th 2010, 03:19 PM
Niles_M
Thanks, I appreciate it.