Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 4 different commands in LOOP programming language:

    y=Val(x)=copy x and put it in register y

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.

share|improve this question
up vote 1 down vote accepted

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

loop x times {
  loop z times {
share|improve this answer
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 ? – Voyage Mar 10 '13 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).” – Christopher Creutzig Mar 10 '13 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. – Christopher Creutzig Mar 10 '13 at 16:14
...and how do you obtain a negative number using this method? If X = 0, the result will not be -1. – Mason Wheeler Mar 10 '13 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. – Christopher Creutzig Mar 10 '13 at 20:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.