The Sins of K&R

Jim Mann jmann at angmar.sw.stratus.com
Thu Sep 27 22:39:08 AEST 1990


In article <12180 at crdgw1.crd.ge.com>, volpe at underdog.crd.ge.com
(Christopher R Volpe) writes:
|>In article <31604 at nigel.ee.udel.edu>, shearer at cis.udel.edu (Rob Shearer)
|>writes:
|>|>
|>|>I do this alot:
|>|>
|>|>  ch = getch();
|>|>  switch (ch) {
|>|>    case 'q':
|>|>    case 'Q':
|>|>    case 27 :
|>|>    case 13 :
|>|>      exit_menu = 1;
|>|>      break;
|>|>    case 'a':
|>|>      do_a(); break;
|>|>   ...etc
|>|>  }
|>
|>How about combining the "let's make break implicit" idea with the
|>"lets add ranges and lists" idea and solve everybody's problems? E.g.:
|>
|>ch = getch();
|>switch (ch) {
|>  case 'q','Q',27,13:
|>    exit_menu=1;
|>  case 'a':
|>    do_a();
|>  ...etc
|>}
|>
This still doesn't do everything you might want. It doesn't handle
the situation in which you do something for one case and then 
fall through to the next to do some additional stuff:

switch(ch)
     {
     case 'a':
	   do_a();
     case 'b':
           do_a_or_b();
	   break;
	.
	.
	.
     }     

	
                                    

Jim Mann
Stratus Computer
jmann at es.stratus.com



More information about the Comp.lang.c mailing list