This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I am trying to write a switch statement which will check the return statements from 3 called up methods ("february", "century", and "leap")...and based on the boolean values they return to "daysInMonth" certain commands are to be carried out......
is ist possible to use the code segment below the way i have done? if not, what corrections could i make,....any suggestions?
because i was made to understand that if you had several "if statements" following each other you could put them all together into a switch control structure?
so if i have 20 possibilities i would have to put these all into "if statements"?
tahnx!
Ernest Friedman-Hill
author and iconoclast
Marshal
Booleans have just two values: true and false. Therefore a "boolean switch" could never have more than two branches. To have more than two branches, you'd actually need more than one boolean value -- i.e., you're testing more than one thing. A chain of if... else if... else statements lets you do just that.
Wolfgang Obi
Ranch Hand
Joined: Dec 05, 2005
Posts: 134
posted
0
okay, this is what I've decided to do.....how about it?
[ May 28, 2006: Message edited by: Wolfgang Obi ] [ May 28, 2006: Message edited by: Wolfgang Obi ]
Wolf- Just a little switch tip. If you're going to take the same action for several cases, it is not necessary to explicitly code the action for each case. Just arrange your cases appropriatley. The following will have the same affect as the switch you coded above.
Originally posted by S Root: Wolf- Just a little switch tip. If you're going to take the same action for several cases, it is not necessary to explicitly code the action for each case. Just arrange your cases appropriatley. The following will have the same affect as the switch you coded above.
why don't we have a break after the If condition below if (((isSchalt == true)&&(!(isCent)))||(isLeapCent == true)) days = dayGroup[1];
It is good programming style to always write the curly braces, {}, althought they are not needed if the clause contains only a single statement. The curly braces are a general indicator in Java of a compound statement. This is known as a block of code. (See here) [ May 29, 2006: Message edited by: wise owen ]