On Fri, 20 Jan 2012 08:55:06 +1100, RenatoL <rex...@gmail.com> wrote:

Just curious: why in D we are not obligated to use break in every
branch of a swicth structure?

a) C/C++ compatibility
b) Walter likes this construct and uses it in his code.

I use a language that enables the coder to choose to use fall through or not. By default, falling through is disabled, so to produce the D effect one can code ...

        switch i with fallthru do
                case 1 then
                writeln("You wrote 1")
                case 2 then
                writeln("You wrote 2")
                case 3 then
                writeln("You wrote 3")
                else case then
                writeln("I said: 1 or 2 or 3!")
        end switch

or alternatively ...

        switch i do
                case 1 then
                writeln("You wrote 1")
         fallthru
                case 2 then
                writeln("You wrote 2")
         fallthru
                case 3 then
                writeln("You wrote 3")
         fallthru
                else case then
                writeln("I said: 1 or 2 or 3!")
        end switch


--
Derek Parnell
Melbourne, Australia

Reply via email to