Programming, C, PHP. There are so many programming languages out there. If you are a programmer of any kind, you are most likely familiar with the Case/Switch statement in C++ This is simply a way in programming for you to do different things depending on the value of a variable. For example..if your working with a variable named abc. You might want to do different things depending on what the value is. The long way would be to put down a long if/else statement to deal with each potential value type. The easy way is to use a simple switch/case statement. No matter what language you are using, this will come into play at some point.
If you are using PHP a switch/case statement might look like follows:
$variable = 'test';
switch($variable) {
case 'test':
// do something
break;
case 'test2':
// do something
break;
case'test3';
// do something
break;
}
?>
That is a simple example. It’s similar to JavaScript, but with a little different syntax. Now here is the tricky part. I don’t know every language out there. However, quite a few of them have the same type of structure of Switch/Case statements. Then suddenly C++ throws you a loophole. In working with C++ it’s just about the same as PHP. Except for one strange thing. If you initialize a variable inside of a switch/case statement you have to use brackets around each interior case when you are initializing a variable. Just something tricky that I had to figure out with a lot of trial and error.
I have programming experience in a variety of languages, so in the future I’ll create other blog posts for programming to try to help other people learn how to program, and solve issues they are having. A case/switch statement is a simple example. In a few weeks I will post some programming blogs teaching various aspects of the world of programming and basic programming knowledge and troubleshooting.
Other archived blog posts can be found here.
More information about C++ programming can be found here.