/* decreases x - 1 */ while (x > 1) { x = x / 2; }

/* decreases x */ while (x > 0) { x = x - (1 / n); n = n + 1; }

posted by deskin

]]>int x = 1, n = 100000; while (x > 0) { x = x - (1 / n); n = n + 1; } n = 0x7ffffffe, x = 1 n = 0x7ffffff, ... n = 0x8000000, ..., n = -1, x = 2 n = 0 -> div by zero

posted by arcnet

]]>

What you are getting at, though, is correct, namely that what is necessary and sufficient for the loop to terminate is that the successive iterations can be mapped to strictly decreasing values in some well-founded order.

posted by leino

]]>

Thanks!

Iman

posted by iman.saleh

]]>Rustan

posted by leino

]]>