But the real challenge in the SO question is the 'going back in time' part,which I have trouble to understand : how can you modify x and y through a multiplication and a comparison?
It can be done using setjmp/longjmp, see C implementation for an example: http://homepage.mac.com/sigfpe/Computing/continuations.html