Human factors matter a lot more than technical details. The simplest way is to simply memoize that for loop looks like this:
for (0; n)
It means, we are working with n elements. This is then transcribed into general looping construct like this:while (i < n) {
// increment i
}
This form works for any increment.For is just a specialization of general repetition, a syntactic sugar of sorts, and it translates identically:
for (int i = 0; i < n; i++)
Extended approach of checking (i >= min) && (i < max) reduces human factor impact - regardless of how insides change or what is passed into construct, the code remains stable.
And if correctness matters, then either Ada or full invariant verification must be done anyway, so again, the style of for loop becomes irrelevant.
One can argue major or minor points here, but the Principle of least surprise always applies. Don't surprise me with exotic termination conditions or extravagant for constructs. It has all to do with common approach. Since != is uncommon, I'll need to first turn off the warning light that goes off in my head and then double check to see that author truly intended what is written.
It's simple - you might have studied with The Master, but the code I'll encounter will be written by a script kiddie who treats loop conditions as guidelines rather than rules.
It's the same thing, no?[/quote]Not quite, that is legacy fallback. Correct version would be:std::for_each();
which does the proper thing - it eliminates for/while and instead applies operator to range. Iterators are also bound to range and possibly range checked. If used properly, they can never be invalid (std::advance and similar).
has contributed to the works of Stroustrup[/quote]
That guy invented C++. That's borderline insanity