But your case is wrong anyways because i <= INT_MAX will always be true, by definition. By your argument < is actually better because it is consistent from < 0 to iterate 0 times to < INT_MAX to iterate the maximum number of times. INT_MAX + 1 is the problem, not < which is the standard reason to write for loops and the standard for a reason.
You’re right, that’s what I get for not having written a line of C in what 15 years. Bonus challenge: write foriini32::MIN..=i32::MAX in C, that is, iterate over the whole range, start and end inclusive.
(I guess the ..= might be where my confusion came from because Rust’s .. is end-exclusive and thus like <, but also not what you want because i32::MAX + 1 panics).
But your case is wrong anyways because
i <= INT_MAXwill always be true, by definition. By your argument<is actually better because it is consistent from< 0to iterate 0 times to< INT_MAXto iterate the maximum number of times.INT_MAX + 1is the problem, not<which is the standard reason to write for loops and the standard for a reason.You’re right, that’s what I get for not having written a line of C in what 15 years. Bonus challenge: write
for i in i32::MIN..=i32::MAXin C, that is, iterate over the whole range, start and end inclusive.(I guess the
..=might be where my confusion came from because Rust’s..is end-exclusive and thus like<, but also not what you want becausei32::MAX + 1panics).for (int i = INT_MIN; ; i++) { ... if (i == INT_MAX) break;}