I am new to mathematica and currently learning it by solving some basic problems.
I am trying to arrange a list in ascending order using a detailed IF loop. For instance if we start out with $\{1,65,40, 155, 120, 122\}$. My output should be $\{1,65, 155\}$. However my code yields a different output. Here it is:
Sample = {1, 65, 40, 155, 120, 122};
(i = 1;
newSample = Sample;
Label[1];
newSample = Delete[newSample, i + 1];
If[newSample[[i]] >= newSample[[i + 1]], Goto[1], i = i + 1 && i <= Length[newSample]-1 ];
Print[newSample]
)
{1,40,155,120,122}
I would greatly appreciate any help on why this is happening and how to fix this code. (I would also be interested in seeing some slick ways to write this same code using other(?) built in functions but my main priority is fixing the above code).