|
Re: Visual Basic
Yes, that's a switch-case statement. However, a fall-through switch case statement is a little different:
int i,x,y,z;
switch(i)
{
case(1): x = 4;
case(2): y = 4;
case(3): z = 4;
break;
default: x = y = z = 0;
break;
}
This code sets:
x,y,z to 4 if i = 1
y, z to 4 if i = 2
z to 4 if i = 3
x, y, z to 0 else
It's called "fall through" because there are no break statements in the early set of cases. This means that the case i == 1 falls through to i == 2 which in turn falls through to i == 3. There are many situations where this is useful, especially if the cases for i are not mutually exclusive.
From my understanding of VB, the above block would have to be coded this way:
Select(i)
case(1):
x = 4
y = 4
z = 4
case(2):
y = 4
z = 4
case(3):
z = 4
default:
x = 0
y = 0
z = 0
End Select
I might be wrong about that VB switch statement, but I'm pretty sure it doesn't support the fall-through idea.
de KG2OV
|