our assignment is that we have make a plot for the possition of 1's
From the recursive function
if a[n-1] is even then a[n]=a[n-1]/2
and if a[n-1] is odd then a[n]=3*a[n-1]+1
where we have to find at which possition the first 1 occures for 10000<=a[n]<=2.
So for this we have to do a for loop with if statment
list = {};
b[n_] := b[n] = If[EvenQ[b[n - 1]], b[n - 1]/2, 3*b[n - 1] + 1];
For[b[1] = 10000, b[1] =2, b[1]--,
AppendTo[list, Min [Position[Table[b[n], {n, 1, 30}], 1]]]];
list
ListPlot[list]
The problem we get is that every outprint will be for b[1]=10000 that is 30. And this is not what we were expecting. We know that the problem is that we can not use Clear[b] in a good way inside the loop, but is there any other way that this problem can be solved. ? For this the lector has adviced us to use ListPlot.


b[n_] := If ..so you dont need to clearbeach time you changeb[1]– george2079 Sep 24 '14 at 10:40Forloops andAppendTo? That's just depressing. See here: http://mathematica.stackexchange.com/a/18396/8 – Verbeia Sep 24 '14 at 11:16ForandAppendTois the student's interpretation of the task (and not the preferred approach). – bill s Sep 24 '14 at 12:15