Date: Tue, 10 Feb 1998 21:32:31 -0800 (PST) Message-Id: <199802110532.VAA05804@adit.ap.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: nguyen2 AT tidalwave DOT net_REMOVE (Linh Nguyen), djgpp AT delorie DOT com From: Nate Eldredge Subject: Re: Beginner, switch statement in DJGPP Precedence: bulk At 08:34 2/10/1998 GMT, Linh Nguyen wrote: >Hi. I use Borland C++ 5 at school, and coded the switch statement as >follows... > >switch(Num) >{ >case 1, 10, 6: cout << "Test"; break; >....... and so on and so forth >} That is a nonstandard extension made by Borland. It is not part of Standard ANSI C, so if you use it your program is not portable. > >but in DJGPP, it won't let me do that, it only lets me have one >possibility for each case statement, so it would be like this.. > >case 1: ... >case 10: ... >case 6: ... That's correct. However, since by default in C a `switch' case falls through, you can do this: switch(foo) { case 1: case 10: case 6: cout << "Test"; break; /* ... */ } GCC does provide an extension to let you use ranges in `case' expressions, so that case 1 ... 4: /* stuff */ is equivalent to: case 1: case 2: case 3: case 4: /* stuff */ See the info page "gcc" "C Extensions" "Case Ranges" for more info and caveats. Note that this also is not standard. > >Is there any way around this? Thanks for any help! > > > Nate Eldredge eldredge AT ap DOT net