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.
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.
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.
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.
Become a Member to join the conversation.