switch statements require the following elements:
- The switch keyword followed by a pair of parentheses holding its condition
- A pair of curly brackets
- A case statement for each possible path ending with a colon:
- Individual lines of code or methods, followed by the break keyword and a semicolon
- A default case statement ending with a colon:
- Individual lines of code or methods, followed by the break keyword and a semicolon
In blueprint form, it looks like this:
switch(matchExpression)
{
case matchValue1:
Executing code block
break;
case matchValue2:
Executing code block
break;
default:
Executing code block
break;
}
The highlighted keywords in the preceding blueprint are the important bits. When a case statement is defined, anything between its colon and break keyword acts like the code block of an if-else statement. The break keyword just tells the program to exit the switch statement entirely after the selected...