C’s switch()
- It is a conditional statement that permits enumeration of discrete cases, instead of relying on boolean expressions
- It’s important to
break;
between each case, or you will “fall through” each case (unless that’s expected)
int x = GetInt();
switch(x)
{
case 1:
printf("1!\n");
break;
case 2:
printf("2!\n");
break;
case 3:
printf("3!\n");
break;
default:
printf("Sorry!\n");
}
Ternary
int n = (expr) ? 5 : 6;
- same with 1 set of if else