Boolean Expressions and Conditionals
Conditional branching using Boolean expressions are how we as programmers make decisions in our programs. They allow us to not be limited to following an identical pathway through our code each time, but rather empower us to take different forks in the road, allowing for different behaviors or different user experiences. In this section we discuss conditionals, their utility, and the three main types of conditionals offered by C – if-else, switch, and ?: (the ternary operator) as well as the Boolean expressions (<
,>
, <=
, >=
, ==
, !=
, &&
, ||
, and !
).
-
Lecture (Part 0)
-
Lecture (Part 1)
-
Shorts
-
Notes
-
Thought Questions
- What is a good sample use case for if-else? How about switch? When would you want to use ?:?
- What does translating simple conditionals to pseudocode look like?
- Why is it important that we be able to make decisions in our code?
-
Problem