select(VB) / switch(C)

Status
Not open for further replies.
Why use it? Because it simplifies a long if-else if-else if-else statement.

(I'm talking about a C# statement, but you'll get the idea)
It's easier for me to do this:
Code:
switch(someString)
{
    case "Case 1":
         //some statements if someString == Case 1
         break;
    case "Case 2":
         //some statemsnt if someString == Case 2
         break;
    default:
          // some statements if someString doesn't match anything else
          break;
}

Over doing something like this:
Code:
if(someString == "Case 1")
{
    // some statements
}else if(someString == "Case 2")
{
    //some statements
}else
{
   //some statements
}
Now that's just simple example where it didn't really matter, but imagine a situation where you had to check 50 different values of someString, a switch statement would be much faster and easier to execute.
 
Simply because different people made different languages, whats the point of a new laungage if you have one just like it?

Also, the big thing a case statement is good for is when you need to add up a multitude of things, like say:

$500 = plasma tv
$400 = computer
$300 = a bike
$200 = 20" tv
$100 = pair of shoes

If someone has a value of 500, they get All of that, by placing it in a case statement, starting at 100, through 500 at the end, if they have 400, they get all the values, and after the variable does not equal 500, they hit the statement 'break' (which the guys used above) to exit the whole switch. This is especially useful, say if you had things rangin from $100,000 to $50, where the prizes were cumulative.
 
Status
Not open for further replies.
Back
Top Bottom