Re: "case" or better? (2.6 suggestion mode)
- Posted by "Juergen Luethje" <j.lue at gmx.de> Apr 03, 2005
- 487 views
Pete Lomax wrote: <big snip> > Three points sprang to mind: > 1) the main argument for case is the "fall through" > 2) the main argument against case is the "fall through" / forgetting > break. > > 3) I vote No Thanks. > > It just reminded me why case/select sucks. It depends on the concrete way how the "case" statement is implemented. Yes, in C, there is a "fall through" when "break" is not used. But e.g. in PowerBASIC, there is no "break" (or equivalent) keyword: year = 2001 select case year case 1900 to 1910, 1912 print "Once upon a time ..." case 1960 to 1969 print "In the sixties ..." case > 2000 print "Recently ..." case else print "Hmm?" end select This is equivalent to
integer year year = 2001 if (1900 <= year and year <= 1910) or year = 1912 then puts(1, "Once upon a time ...\n") elsif 1960 <= year and year <= 1969 then puts(1, "In the sixties ...\n") elsif year > 2000 then puts(1, "Recently ...\n") else puts(1, "Hmm?\n") end if
In PowerBASIC, there is no "fall through" possible at all. Of course, when you say: | 1) the main argument for case is the "fall through" then there is no main argument for implementing the "case" statement this way. Regards, Juergen