4 ms·
If your for loop is for a 0-based language, it's wrong because it starts with 1. If it's for a 1-based language, it's wrong because it compares with "<" and no
by unwind 14y ago
If your for loop is for a 0-based language, it's wrong because it starts with 1.
If it's for a 1-based language, it's wrong because it compares with "<" and not "<=".
So, I guess that proves your point that it's error-prone. :)
In C, the idiomatic way is (as you surely know) "for(i = 0; i < n; ++i)".
- justincormack 14y agotypo, the second one was supposed to be 0 based... although that shows how off by 1 errors occur.