Uploaded September 2012 | Updated September 2026, 2 weeks ago
Today we'll look at switch statements, cases and their default code blocks. It's an interesting control structure. It's possible to program without using switch at all, but switch is often a clearer than a collection of if, else if and else.
The example at 7:10 is wrong. The output I've described is right but my reasoning is not. As pointed out by FullRock, the case 20 will run regardless of the value of "j". After a case executes, C++ does not check the conditions again and continues executing until it finds break.
Today we'll look at switch statements, cases and their default code blocks. It's an interesting control structure. It's possible to program without using switch at all, but switch is often a clearer than a collection of if, else if and else.
The example at 7:10 is wrong. The output I've described is right but my reasoning is not. As pointed out by FullRock, the case 20 will run regardless of the value of "j". After a case executes, C++ does not check the conditions again and continues executing until it finds break.










