If...Then
If...then is a way of thinking that allows us to make decisions based on Logic.
It can help us make decisions in mathematics, computer science and everyday life.
Here we explore the basics of using if...then logic, as well as how to use "and", "or" and "not".
Using If...Then
The basic structure of an if...then statement is simple:
- If a condition is true, then something happens.
Example: If it is raining, then I will take an umbrella.
In that example, the condition (it is raining) triggers the decision (take an umbrella).
There are two parts:
- The if part is the condition that must be true for the statement to be true.
- The then part is the result that will happen if the condition is true.
And Or Not
We can combine conditions together using and, or and not.
It works like this:
- If (some combination of conditions) is true, then something happens.
And
We can use and when both conditions have to be true for the statement to be true.
Example: If it is raining and windy, then I will wear a raincoat.
If it is only raining or only windy then we don't make the decision. But if it is both rainy and windy we want that coat!
Example: If I am hungry and I have enough money, then I will buy lunch.
If we aren't hungry or don't have money we won't be buying lunch!
Or
Or is used when either condition (or both!) trigger the decision.
Example: If it is raining or snowing, then I will take an umbrella.
In that example, either condition (it is raining or it is snowing) can be true for the decision to be true. A mix of rain and snow also works.
We can also have many conditions!
Example: If it is raining or snowing or cloudy, then I will take an umbrella.
The result (take an umbrella) will happen if any of those conditions are true.
Not
We can also make the decision when a condition is not met:
Example: If it is not sunny, then I will take an umbrella.
Numbers
Numbers are often part of the decision:
Example: If you have 8 items or less, then you can use this checkout.
Example: If the time is 8:00 and it is a weekday, then you should be out the door heading for the bus stop.
Example: If you are not in the top 20%, then you must do extra study.
- If the light is red, then you must stop.
- If the light is green, then you can go if it is safe.
Conditional
Conclusion
If...then, and, or and not are powerful ways to make logical decisions.
By understanding the basics of this logic you can make better decisions in your everyday life.