In this lesson our instructor talks about conditional control structure. First, he discusses elseif statement, multiple elseif statements, and adding an else statement. Then he talks about switch() statement, default case, and some coding conventions. He ends the lesson with a helpful homework challenge.
The elseif statement is a conditional control structure that can
be associated with an if statement. If an if statement’s test condition is
FALSE and an associated elseif statement’s test condition is
TRUE , the elseif’s statement group gets executed.
Multiple elseif statements can be associated with a single if statement.
An else statement can be appended to the end of a series of if/elseif statements
so if none of the if/elseif test conditions evaluate to TRUE , then the else
statement group will be executed.
A switch() statement is used to compare a single test expression
against different values, known as cases , and then evaluate any code
associated with the case it matches.
Case values can only be expressions that evaluate to one of the scalar data types
(int, float, string, bool) or NULL .
A switch() statement executes all statements it encounters after a matching case
is found until either a break statement or the end of the switch()
statement is reached, whichever occurs first.
A default case can be assigned to a switch() whose associated statement(s)
will be executed if the test expression did not match any case in the switch().
Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.