View Single Post
Old Jan 16th, 2007, 7:49 PM   #7
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,126
Rep Power: 5 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by Arevos View Post
The default behaviour of a switch statement is to fall through each case to the next one. That's why you usually have to put a "break" at the end of each case block. Remove each "goto" line and it should work as you wish.
One problem with this is C# doesn't like these fall-throughs. It allows them are when there is no code between case labels. That is,
case 0:
case 1:
  <code here>
  break;
is okay, but
case 0:
  <code here>
case 1:
  <code here>
  break;
is not. I also believe that if the case block contains an unconditional return (or more accurately, all code branches inside that case block contain a return), the compiler will accept it (since the return will prevent fall-through). Otherwise, the compiler bitches; I believe the rationale is that it's a common source of coding errors, and (to some) bad style.
Quote:
Originally Posted by Arevos
As a rule of thumb, "goto" should never be used. I suspect there are extremely rare cases where it might be useful, but I have yet to discover any of these cases. Steer clear of goto.
I wholeheartedly agree.

@OP: You might want to make it clear whether your numbers for month and day are zero-based or one-based. For example, is January zero, or one? You could look into using an enum for the months (and days of the week).

Also, your reason for using a switch block escapes me. Since the pieces of code progress in sequential order, and always fall through, what is the point? Just stick 'em in series, and ditch the switch. If your purpose is because the user doesn't always need to enter the higher-order values (ie, if they skip the year, it will use the current one, or some other defined default), then you could use a switch inside a loop, and then increment or decrement the switch expression in the loop.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick

Last edited by lectricpharaoh; Jan 16th, 2007 at 8:04 PM.
lectricpharaoh is offline   Reply With Quote