I almost never see a for
loop like this:
for (int i = 0; 5 != i; ++i)
{}
Is there a technical reason to use >
As you can see from the other numerous answers, there are reasons to use < instead of != which will help in edge cases, initial conditions, unintended loop counter modification, etc...
Honestly though, I don't think you can stress the importance of convention enough. For this example it will be easy enough for other programmers to see what you are trying to do, but it will cause a double-take. One of the jobs while programming is making it as readable and familiar to everyone as possible, so inevitably when someone has to update/change your code, it doesn't take a lot of effort to figure out what you were doing in different code blocks. If I saw someone use !=
, I'd assume there was a reason they used it instead of <
and if it was a large loop I'd look through the whole thing trying to figure out what you did that made that necessary... and that's wasted time.