# How to define a function having many steps? [duplicate]

I can't transform a simple code into a function. The function should take an integer and return a list of digits in a factorial number system:

X=36177
j = 2; x = {}; While[X > 0, AppendTo[x, Mod[X, j]];
X = Quotient[X, j]; j++]; x


When I use

f[X_Integer] :=
Module[{j, x}, j = 2; x = {};
While[X > 0, AppendTo[x, Mod[X, j]]; X = Quotient[X, j]; j++]; x]


as is recommended I get next message:

Set::setraw: Cannot assign to raw object 36177. >>

Set::setraw: Cannot assign to raw object 36177. >>

Set::setraw: Cannot assign to raw object 36177. >>

General::stop: Further output of Set::setraw will be suppressed during this calculation. >>

What do I do wrong? Please help me with this code.

## 1 Answer

In Mathematica you cannot modify the values of parameters to a function.

Try using local copies of the values, which you can modify, and see if that works for you.

f[X_Integer] :=Module[{j, x, xX}, j = 2; x = {}; xX = X;
While[xX > 0, AppendTo[x, Mod[xX, j]]; xX = Quotient[xX, j]; j++]; x];
f[13]