General Category > Ideas

Switch proposal

<< < (3/3)

bas:
Ahh missed that sorry

I think the common case for a switch is that every case breaks. Fallthrough is a much rarer case. So I think making
all cases break by default is an improvement indeed. Syntax wise, this means the following:
- keyword break is allowed in a case.
- keyword fallthrough is used to indicate that the case will fallthrough (there must be a next case).

I'll put in on the roadmap

bas:
I was thinking about the fallthrough keyword and came up with a situation that requires some thinking.
How would we handle:


--- Code: ---...
case A:
   if (b == 10) fallthrough;
   do_something();
case B:
    ..

--- End code ---

So the fallthrough can be used to 'jump' to the next case. Or only allow fallthrough at the end?

To avoid this complexity, I see that Go (golang.org) only allows fallthrough at the end. So probably that is best..

lerno:
Well, if you look at the alternatives for fallthrough:

(a) fallthrough
(b) goto next
(c) goto case
(d) goto case 4
(e) continue case
(f) next
(g) nextcase

Here obviously b, c, d, e, g all clearly indicate that there's a jump. (d) is even more explicit of course, not to mention flexible.

Navigation

[0] Message Index

[*] Previous page

Go to full version