Re: question about switch, return, break

From: Sean Butler (sbutler@DEVEAST.COM)
Date: 12/19/97


>>
>> switch (mode) {
>>   case SCMD_DROP:
>>     obj_to_room(obj, ch->in_room);
>>     return 0;
>>     break;
>>   case SCMD_DONATE:

>The break really isn't needed there because of the return statement, but
>some compilers will scream and shout if the break isn't there because
>according to the standards it has to be there.

I don't think this is true:

        char c;

        c = get_a_char();

        switch (c) {
          case 'a':
                printf("case a");
          case 'b':
                printf("case b");
          case 'c':
                printf("case c");
          default:
                printf("always print this");
        }

If gcc doesn't like this code, gcc is not ansi compatible.
(which we know is not the case.)  break is not needed in a
switch statement.  It just gives us the ability to stop execution after
a match is made.  If we don't break, then the rest of the cases get
executed.
--
Sean Butler
sbutler@deveast.com


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST