I do not understand the flaw in my logic here. What I want is a list whose elements are integers with squares less than 1000 and that are prime.
----------------
Clear[listPopulator];
listPopulator := (
Clear[intList];
intList = {};
For
[
k = 1,
k^2 < 1000,
k + 1,
If[PrimeQ[k^2], AppendTo[intList, k], AppendTo[intList, k]]
];
intList;
)
-----------------
When I attempt to define this function I need to quit the kernel because I get stuck in an infinite loop (is what I'm assuming). My guesses are: 1) Maybe it's the fact my counter and control variable are the same. 2) Maybe intList being defined in the the function 'listPopulator' has something to do with it. I am going to experiment with these right now.
Also, I realize my 'false' statement in the If command makes no sense, but I wasn't sure what to put there if I wanted the If statement to do nothing in the case of a 'false'. At the moment I am more concerned with making sure intList is even populated.
Any tips would be helpful. Don't feel the need to 'give' me the answer.