Louis I. answered 05/26/19
Computer Science Instructor/Tutor: Real World and Academia Experienced
Well, it better describes your loop condition doesn't it - and kinda feels safer, no ;-)
// 1) from 1 to 10
for(int i = 1 ; i < 11 ; ++i ) {
// loop body
}
// 2) from 1 to i NOT 11 ??
for(int i = 1 ; i != 11 ; ++i ) {
// loop body
}
Why do I view the first loop implementation as "safer"?
Well,imagine that some odd processing on the loop caused the value of i to be set beyond 11 ...
loop condition #2 would allow us to spin into infinity - loop condition #1 would not.
But primarily, coding is largely about expressing our intent.
for(int i = 1 ; i < 11 ; ++i ) {}
is unambiguous and articulates out intent better than
for(int i = 1 ; i != 11 ; ++i ) {}