Switch and break
Derek
ddparnell at bigpond.com
Thu Jan 19 14:18:21 PST 2012
On Fri, 20 Jan 2012 08:55:06 +1100, RenatoL <rexlen at 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
More information about the Digitalmars-d-learn
mailing list