Earlier today in a post I saw a user correct another to use && instead of 'and'
Is there any advantage to this? I didn't want to hijack that thread so I am asking here.
I've had no issue using 'and' in place of && as well as 'or' in place of ||, seems the compiler takes care of that.
Just trying to figure out if I should dismiss this as personal preference or if there is actually a reason for it.
I guess it avoids the possibility of only typing & instead of && and | instead of ||.
Although you may think they are equivalent, && permits evaluation short-circuit (which is important to avoid, for example, null pointer dereferencing) but I'm not sure & necessarily would.
I believe the answer is quite obvious - 'and' is much easier to read than '&&'. Actually, some fonts render the pipe '|' very closely to 'I' or 'l' or '1' and any help with distinguishing it in some expression is welcome with me.
I see some doubts posted concerning whether they are equivalent. The alternate keywords like 'and' and 'or' and 'not' are completely equivalent to '&&', '||', and '!'. There is absolutely no syntactic or semantic difference. Except, as they are composed of alphanumeric characters, they must use white space to remain separate from alphanumeric identifiers and keywords.
If you desperately need example, write two functions - one returns true, the other false.
Both print that they have been called.
Put calls to the functions in an if statement with an "and".
If the left-most call returns false, the right-most will not even be called