You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
- equality is symmetric. hence, the two ifs are the same thing.devnull– devnull2014-09-18 04:48:57 +00:00Commented Sep 18, 2014 at 4:48
- 1@devnull While technically true, there is quite a bit of variance in C/C++ standards as to which is better because of the possibility of silent typos.Chris Pitman– Chris Pitman2014-09-18 05:13:59 +00:00Commented Sep 18, 2014 at 5:13
- In addition to the answers given, writing if ('constant' == $variable) can also eliminate bugs. If you mistakenly write (a = true) instead of (a == true) you've introduced a bug in your code. (true = a) will give a compiler error.Dennis_E– Dennis_E2014-09-18 08:40:03 +00:00Commented Sep 18, 2014 at 8:40
- Just wanted to add that having the constant first in the comparison is referred to as a Yoda condition (or notation apparently): > Using if(constant == variable) instead of if(variable == constant), > like if(4 == foo). Because it's like saying "if blue is the sky" or > "if tall is the man". Coding Horror New Programming Jargon Wikipedia Yoda Conditions (Sorry I would rather have added this as a comment but I don't have the reputation)Paddy– Paddy2014-09-18 08:53:01 +00:00Commented Sep 18, 2014 at 8:53
- both are wrong, the correct formulation is (a)kevin cline– kevin cline2014-09-18 09:07:40 +00:00Commented Sep 18, 2014 at 9:07
| Show 2 more comments
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
- create code fences with backticks ` or tildes ~ ```
like so
``` - add language identifier to highlight code ```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible) <https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. design-patterns), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you