I cannot realise if it is a duplicate question. Sorry; if it is. This
fl[x0_] := Module[{x = 1}, While[x <= x0, If[Mod[x0, x] == 0, Print[x]]; x++]] print the factors of $x_0$. But a printed value cannot be reused. How to put those values in a list to reuse them. I have tried something like that
fl[x0_] := Module[{x = 1 }, A = {}; While[x <= x0, If[Mod[x0, x] == 0, Append[A, x] && Print[A]]; x++]] but it return empty lists.
AppendToinstead ofAppend. $\endgroup$FactorInteger$\endgroup$Divisors@...will be the fastest to accomplish goal, and should you feel the need to go through self-made machinations vs using a bult-in,With[{r = Range@#}, Pick[r, Mod[#, r], 0]] &will handily clobber the existing answers in performance. $\endgroup$