I am wondering, if in the LOOP programing language, whether instances of the LOOP x DO P END are defined to stop in the case $x < 0$.

The definition only says "Execute $P$, $x$ times" for the above program.

IT is perfectly clear for $x = 0$. However, I believe in order to keep the language simple the definition doesn't extend to the case $x < 0$.

If it were possible, then it would for instance basically shorten a $x_1\ div\ x_2$ operator to just one line:

x_0 = 0;
LOOP x_1 DO x_1 = x_1 - x_2; x_0 = x_0 + 1; END

If it is not possible, is there any other reason except for reasons of convention?


Variables in LOOP programs are non-negative, so the problem never arises; the instruction $x_1 = x_1 - c$ assigns $x_1$ the value of $\max(x_1-c,0)$.

Note that the instruction $x_1 = x_1 - x_2$ isn't allowed: the second operand has to be a constant. However, since $x_1 = x_1 - x_2$ can be implemented in LOOP, the programming language "LOOP with instructions of the form $x_i = x_i - x_j$" has the same power as LOOP.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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