This is a vivid example of early optimization .... IMHO, this is what programmers new to their craft tend to worry about. If you need to worry about this, learn to compare and project your code so that your concerns are based more on evidence than on assumptions.
Talk with your specific questions. First, <= not implemented as two testing operations for < and == separately in any C compiler I have encountered in my career. And that includes some monumental silly compilers. Note that for integers a <= 5 is the same condition as a < 6 , and if the target architecture only needs to use < , the code generator will do this.
Your second concern that while (i != 10) can be more efficient is causing an interesting defensive programming problem. First, there is no effectiveness in any reasonable target architecture. However, this increases the likelihood of a small error causing a larger glitch. Consider this: if some line of code inside the loop body is changed i , say, making it more than 10, what could happen? How long will it take to complete the cycle and will there be any other consequences of the error?
Finally, when you wonder about this, it is often worth figuring out what code your compiler uses. Most compilers provide a mechanism for this. For GCC, learn about the -S option, which will cause it to generate assembly code directly instead of creating an object file.
source share