Locked lesson.
About this lesson
Understanding conditional statements using switch.
Exercise files
Download this lesson’s related exercise files.
Switch.docx59 KB Switch - Solution.docx
59.5 KB
Quick reference
Switch
A switch is a type of a conditional, similar to an If statement.
When to use
Use switches when you have lots of different cases to test against.
Instructions
Switches act sort of like if statements. The general format is:
switch(expression){
case a:
//code block;
break;
case b:
//code block;
break;
default:
//code block;
}
Hints & tips
- Switches are similar to If statements
- Use a switch when you have lots of cases to test against
Lesson notes are only available for subscribers.