There are at least two differences:
the first one will iterate 5 times (from 0 to 4), while the second one will iterate 6 times (from 0 to 5).
This is a logic difference, and it depends on what you need to do.
If what you meant for the second example was i<=4
(versus i!=5
) you shouldn't bother: any compiler will always be able to optimize such a trivial expression even with optimizations turned off.
the second difference is the use of operator ++
: in a case you use the prefix version, while in the other the postfix version.
This doesn't make difference for native types, but could do some difference with user defined types (ie classes, structs, enums, ...), since the user could overload the operator, and the postfix one (var ++
) could be a little slower sometimes.