Most or all of these answers are ignoring the purpose of fall-through (or Goto Case):
Not having to reuse code or create a special function just for a few areas in the same Select Case
/If Tree
so that you can avoid reusing code, like this Javascript.
These samples are pretty contrived. There are definitely ways to simplify this scenario, but a lot of times, there aren't.
let pay = 100, perks = '';
Switch (EmpObj.type) {
Case 'Boss':
pay = pay * 10;
perks = '11 month vacation per year';
Case 'Manager':
pay = pay * 3; // This will make Boss pay * 30
Case 'Employee':
EmpObj.pay = pay;
EmpObj.perks = perks;
break;
Case 'Intern':
EmpObj.sendMessage("Go get some coffee.")
}
In VB.net, the same code would be
dim pay = 100, perks = "";
Switch (EmpObj.type) {
Case "Boss":
pay = pay * 30
perks = "11 month vacation per year"
Case "Manager":
pay = pay * 3
Case "Employee":
Case 'Intern':
pay = 0
EmpObj.sendMessage("Go get some coffee.")
End Select
EmpObj.pay = pay;
EmpObj.perks = perks;
Case, in simple situations, is easier to read and write than a comparative if-branch, but the fall-through is the best part.
There's a way that works now at least in Visual Basic 2017. It's not the prettiest though.
GoTo Case "[label]"
and Goto [Case-label]
still do not work.
The label (Number2
here) must be after the Case
. That was the most disappointing part.
dim Value = "1"
Select Case Value
Case "0"
' do nothing, example
Case "1"
MsgBox("one")
GoTo Number2
Case "2"
Number2:
MsgBox("two")
Case "boolean"
MsgBox("three")
' just to show it won't fall through
End Select