Skip to main content

printing - Output of a Print in a list


I'just starting with Mathematica and therefore I was having a small question.


It must be somewhere on Internet but I can't find it.


My question is the following.


I would like to get my values after having computed a Print[...] in a list.


I wanted to print the prime numbers <5


For[i=1,i<5,i++,
Print[Prime[i]];
]



Out:
2
3
5
7

But I would like to get these 4 values such as: {2,3,5,7} How do I compute that? I already tried Print[List[Prime[i]] but that gave me {2} {3} {5} {7}. Thank you!


And if I want to Print the prime values below a certain upperbound, let's say 10.


For[i=1,Prime[i]<10,i++,

Print[Prime[i]; ]


Out: 
2
3
5
7

And I would like to get these values in a list as well, how do I do that? I was thinking about:



Prime/@range@[length[List[Prime[i]<10]]]


Comments