I am trying to produce this same output using a Do loop. Here is the code I have for my For loop.
primelist[m_] :=
(Clear[ourlist];
ourlist = {};
For[
k = 1, (* Initial k value, this is where we start*)
k <= m, (* For loop will stop at the last prime number less than or equal to whatever we specify for "m", this is what were testing *)
k = k + 1,(* value we are testing to determine if prime or not prime, this is the increments *)
If[PrimeQ[k], AppendTo[ourlist, k]] (* appends k to our empty list defined as ourlist = {}, this is where the prime numbers will be stored in list form, this is the body *)
];
ourlist)
primelist[25]
here is the output as expected:
{2, 3, 5, 7, 11, 13, 17, 19, 23}
I know For loops are most common, but I also know you can use a For, Do and While loop to basically do the same thing if you wanted. I'm trying to find a way using the Do loop in my case.
Thanks for any help,
B