K
Keith Thompson
Old Wolf said:You can even do this:
switch(freq)
{
case 1:
if ( variable == 1 )
some_code();
else
case 2:
some_other_code();
}
Also possible is:
switch(freq)
{
case 1:
if ( variable == 1 )
{
some_code();
case 2:
some_other_code();
}
break;
}
Yes, you can. That doesn't mean you should (as I'm sure Old Wolf
knows, but others might not).
There's also Duff's Device; see <http://www.c-faq.com/misc/duff.html>.
Quoting from that page:
In his announcement of the technique to C's developers and the
world, Duff noted that C's switch syntax, in particular its ``fall
through'' behavior, had long been controversial, and that ``This
code forms some sort of argument in that debate, but I'm not sure
whether it's for or against.''