Re: switch state strings!
You can't do it with a switch, but an if statement would work.
One thing you can do is combine your cases such as
Code:
case 'r':
case 'R':
regular();
break;
Re: switch state strings!
Could you please give me an example of an if then statement?
Re: switch state strings!
Quote:
Originally Posted by
Dgameman1
Could you please give me an example of an if then statement?
I really don't mean to sound rude, but an if statement is really, really basic and covered in any C++ text. If you're not familiar with it, you should probably work through a good tutorial before attempting any serious programming. As I'm sure your compiler is pointing out, you have quite a few other syntactical errors. C++ doesn't lend itself to guessing very well.
Re: switch state strings!
Quote:
Originally Posted by
GCDEF
I really don't mean to sound rude, but an if statement is really, really basic and covered in any C++ text. If you're not familiar with it, you should probably work through a good tutorial before attempting any serious programming. As I'm sure your compiler is pointing out, you have quite a few other syntactical errors. C++ doesn't lend itself to guessing very well.
Yeah, I understand.
I meant an if statement that would fit in that context, but I got it all figured out =P
Re: switch state strings!
If a String switch expression cannot be proven by static analysis to be interned, then the compiler will generate a call to the String's intern() method.
Example 1
String state variety = condition ? "fish" : "fowl";
switch (variety) {
case "fish":
return 1;
case "fowl":
return 2;
}
return 3;
In Example 1, it's clear from path analysis that variety can evaluate only to one of two String constants, and since String constants are always interned, the compiler doesn't generate code to intern the switch expression's String value.
U want more questions Click this link http://www.coolinterview.com