So i'm having a bit of trouble with long conditional statements containing more than one operator. For example what would be the equivalent of the following conditional statement with parenthesis separating the statement into parts? (A >= B || B>=A && D==D || !I && F>G). Is it (((A >= B || B>=A) && D==D) || (!I && F>G))? What confuses me is the second set of ampersands since that is ahead of OR in the order of precedence. thx for the help in advance :)
I know this isn't really an answer, though if you have big complex conditional statements, it's generally better to have them in brackets...it stops you making stupid mistakes and makes it easier to read.
in english, and tell me if that is what you thought it should do.
If D is equal to D, (which it obviously always will be) AND A is not equal to B then condition is true.
OR (and this will only ever be checked is A equals B)
If I is false AND F is greater than G then condition is true.
I'm reasonably sure I right with that, and it's probably worth noting that that isn't a good way to right that, this is better:
its ok. its a nice suggestion & i appreciate the input. The reason im asking is because i am currently taking a C++ course at my college & the professor wants us to at least be able to understand what is going on in a statement like this.
@TheMeerkat I understand what u did there. I have no problem simplifying conditional statements. My question is whether (A >= B || B>=A && D==D || !I && F>G) is equivelent to (((A >= B || B>=A) && D==D) || (!I && F>G)) (not the output, but rather the way/order the compiler reads/formats it)
@Sohguanh Thats a rather nice way of organizing it. Still doesn't answer the question, but at least i learned something new :P
Ah right, sorry I hadn't quite understood what you were asking at the start. Sorry I'm no help at all, I always just use loads of brackets all the time and have never bothered trying to learn this as a result. Even if you do know the way they compiler interrupts it, I think it is still better to place things in brackets just to make it much clearer for anyone else reading your code. sohguanh trick looks good if it's important to make it very clear.