In the attached algorithm for computing the quotient and remainder between two numbers, the third-to-last line (q := -(q + 1)) confuses me.
Assuming the second begin...end is an iterative structure, and if q starts at zero, it will alternate between 0 and -1. So that's not the right interpretation. Is it not an iterative structure?
It is to deal with negative division:
$7 \div 3 = 2 ... 1$
Then you want
$-7 \div 3 = -3 ... 2$
This is because you want the remainder to always be $\geq 0$.
$a\div b = c ... d \implies a=bc+d$
$-a=-bc-d=b(-c)-d=b(-c-1)+(b-d)$
Therefore, $c \to -(c + 1), d \to b-d$
Hope this helps.