What if I want to execute code only when an expression in anifstatement is false, not true? Do I need to place the code in anelseclause, and no code after theif?
A.
This is where Boolean logic helps. What you need to do is make the expression evaluate to true for the code you want to run. This is accomplished using the not operator (!) in the expression, like this:
if (!expression) . . .
Q.
How important is the order in whichcasestatements are created?
A.
This all depends on the situation. In the earlier example in which the selected animal was considered and the number of legs it has was displayed, the order of the Dog and Horse case was important. If all case statements contained code, the order has no effect.