Suppose x > y,
we will repetitively decrease x by y. Three cases are possible.
Case 1: We reach the stage where x < y
.
In this case, “if” condition will never be true and x gets no chance to become zero and infinite loop/recursion happens.
Case 2: x = y
. In this case, “else” block runs and y = y -x = 0
.
In this case, x will remain whatever it is currently and would get no chance to become zero and infinite loop/recursion happens.
Case 3: 2*y > x > y
.
In this case, x = x – y
and now, x < y
and we go back to case 1.
Hence, we can conclude that infinite loop/recursion is inevitable unless x = 0 is passed originally.