This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Originally posted by fred rosenberger: you can use as many && and || as you want. i've seen as many as 27 conditions all ANDed and ORed together. Note that this is probably not good programming technique (the 27), but a few are usually ok
What are you saying Fred... 27?!?! What a bowl of spagheti... but am puzzled with something else about if/else statements while doing my homework: When nesting if-else statements, it happens that compiler throws a message "else without if" although in the source code "if" stands where it should be... parentheses are fine too...
You can have any number of && and || operators, but watch you when you mix them. I like to go overboard with parens and be very explicit about how I'm combining things. Humans understand things like "If it's Monday and it's raining or if it's Tuesday and it's snowing ..." and programming languages have rules for interpreting such things, but remember to code for the humans first, the computer second. More parens make it explicit what you mean:
If you find this getting mildly complex (stop far short of 27!) see if you can't break it up. Find names for the combinations and set temporary variables or call tiny methods that do some of the comparisons.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi