Conditions are statements that turn into true or false (kind of like booleans). They usually look like questions or equations, but sometimes they may just be a single variable. Everything in a computer turns into true or false eventually and the way a robot figures out if a question is true or false is by using conditions.
Here’s what we’ll talk about on this page:
We’ll talk about the conditions that look like equations below. Before we do that let’s talk about the conditions that look like a single variable. Sometimes you’ll see a single variable inside of parentheses. These variables will always need to be boolean variables. Because boolean variables are equal to either true or false you don’t need to use an equation to ask a question! The variables itself is the true or false.
You build a condition by using symbols called logic operators. Here are the basic logic operator types:
== equals
Tests to see if the statement on the left is equal to the statement on the right. If the are equal, the condition is true. If they are not equal, the condition is false.
(2 == 3) is false
(3 == 2 ) is false
(3 == 3) is true
Important! Make sure to keep in mind the difference between a single equals sign = and a double equals sign ==. A single equals sign is used to assign (or create) a value for a variable but a double equals signs asks a question. You can think of it this way if you have a hard time, remember that-
- Just one equals sign is going to be really bossy. It tells variables and values what to do.
- Two equals signs won’t be bossy and they will ask each other what they think.