If you have a switch statement and want certain code to be run when the value is one value or another how do you do it? The following code always goes to the defaul
Make it fall through:
int main()
{
int x = 5;
switch(x)
{
case 5:
// there's no break statement here,
// so we fall through to 2
case 2:
cout << "here I am" << endl;
break;
default:
cout << "no go" << endl;
}
return 0;
}
5 || 2
, by the way, evaluates to 1 (or true
, as it is a logical expression), you can try it.