The Wildcats application accepts a drill name. The text Pass selects a passing instruction and Shoot selects a shooting instruction. Any other text receives a fallback instruction.
These statements belong inside an existing method. The string input drill already contains the selected name. Each example chooses an instruction; it does not perform the drill.
string instruction;
switch (drill)
{
case "Pass":
instruction = "Pass to a teammate";
break;
case "Shoot":
instruction = "Shoot at the goal";
break;
default:
instruction = "Choose a supported drill";
break;
}For Shoot, execution begins in the Shoot section instead. The Pass assignment is skipped. After the selected section ends, execution continues after the closing switch brace.
The default section handles a value with no matching case. String matching here is case sensitive: pass does not match Pass.
| Input drill | Selected section | Stored instruction |
|---|---|---|
| Pass | case Pass | Pass to a teammate |
| Shoot | case Shoot | Shoot at the goal |
| pass | default | Choose a supported drill |
| Rest | default | Choose a supported drill |