Hacker News new | ask | show | jobs
by mikeash 4003 days ago
I'd prefer an example along the lines of:

    for(i = j; i < j + 2; i++) {}
With your example it's easy to lose the distinction between "would eventually terminate if you had a fast computer and a lot of time" and "never terminates even in theory." Here, it definitely looks like it should always run two iterations to matter what the numbers are (as long as they're finite), but it doesn't.

Either way, though, it is definitely hilarious!

1 comments

Thanks to undefined behaviour, C compilers can assume that you get exactly two iterations for this kind of loop on ints.