Boolean Contexts
00:00
In the last few lessons, you’ve looked at how the operator works. You’ve learned the syntax for it and the behavior that it has. In these next few lessons, both for part 5 and part 6 of this course, we’re going to take a look at examples of using or
in context.
00:18
First, we’re going to take a look at Boolean context, where we are using Boolean expressions, and then we’re going to take a look at situations where you would make use of objects. Now, in all of these examples that we’re going to see, their purpose is to demonstrate the use of the word or
. You might look at one of these examples and say, “Well, I wouldn’t use an or
for this at all.
00:40
I would code this this way,” and that’s perfectly fine. This isn’t to say what I’m showing you now is the best way to implement a particular type of statement. It’s to illustrate how it would look should we choose to use the or
operator so we can get more experience with the or
operator. The first couple of lessons we’re going to take a look at involve Boolean contexts, places where we actually use Boolean expressions to determine the behavior of our program.
01:11
We typically see that in if
statements and while
loops. In an if
statement, it determines which branch of the if
statement—the then part or the else part—we go to. And within a while
loop, we use a Boolean expression to determine whether or not we go into the loop one more time.
01:28
And so if you know how to use the word or
within your conditions, you can write better loop conditions, you can write better if
conditions, and your program is just overall much better.
01:41 We’re going to take a look at each of those in the next couple of lessons.
Become a Member to join the conversation.