# LOOP program only need inc and zero

I have 4 different commands in LOOP programming language:

``````    y=Zero()
y=Val(x)=copy x and put it in register y
y=Inc(x)=x+1
y=Dec(x)=x-1
``````

Finally I also have

``````    loop n times {
...
}
``````

How is it possible that there is an equivalent loop program to every other loop program which uses only Inc, Zero and the loop?

For me it is not clear how to express the Dec-command using only Inc, Zero and the loop.

Here's one way to code y=Dec(x):

``````y=Zero();
z=Zero();
loop x times {
loop z times {
y=Inc(y);
}
z=Zero();
z=Inc(z);
}
``````
• Thank you. I am little bit confused concerning the double loop. What exactly means. `z=Zero() loop x times { loop y times { z=Inc(z) } }` Does this describe a function g(x,y)=x+y ? Commented Mar 10, 2013 at 14:58
• The inner loop in my code just does `y=y+z`. Your example says “increase `z` `y` times (i.e., `z=z+y`), and do that `x` times, (i.e., `z=z+x*y`).” Commented Mar 10, 2013 at 16:11
• Oh, and in case wonder why my code performs `Dec`: In the first iteration of the outer loop, `z` is zero, so the inner loop does nothing. In the remaining x-1 iterations, `z=1`, so `y` starts at 0 and is increased `x-1` times. Commented Mar 10, 2013 at 16:14
• ...and how do you obtain a negative number using this method? If X = 0, the result will not be -1. Commented Mar 10, 2013 at 17:51
• Loop doesn't have negative numbers. `x=Zero(); x=Dec(x);` makes `x` equal zero, according to the language web page (and the wikipedia page linked above). Otherwise, you're of course right. Commented Mar 10, 2013 at 20:39