First code:
if(i==0) {// do instructions here}
Second code:
if(0==i) { // do instructions here }
What is the difference between the blocks?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Functionally, there is no difference.
Some developers prefer writing the second format to avoid assignment typos(in case you miss a
=), so that compiler warns of the typo.The second is famously known as Yoda Condition.
I say there is no difference because, you cannot guard yourself against every minuscule detail and rely on compiler to cry out aloud for you.If you intend to write a
==you should expect yourself to write a==and not a=.Using the second format just leads to some obscure non-readable code.
Also, most of the mainstream compilers warn of the assignment instead of equality typo by emitting an warning once you enable all the warnings(which you should anyways).