Control Structures and Conditionals :3
Ft. Catherine, Nicole, Julia and Maria
Agenda for Today
The If Statement
Ex:
The print statement will not execute since the condition in the if statement is false.
For general use:
Inequalities
== (equality)
!= (inequality)
> (greater than)
< (less than)
>= (greater than or equal to)
<= (less than or equal to
Note About Inequalities
Instead of:
Do:
Instead of:
Do:
Boolean Operators
&& (AND)
|| (OR)
! (NOT)
*You can find the key for OR above the enter key
Operator Precedence and De Morgan’s Laws
Order of precedence:
De Morgan’s Laws
They are:
Boolean Operators Examples
If a = 5, b = 2, and c = 4, are the following true or false?
!(a != 4) && b > 0 || c >= 4 && a > b
!(a != 4) && (b > 0 || c >= 4 && a > b)
!(a != 4) && b > 0 || !(c >= b) && a > b
(!(a != 4) || b > 0 || !(c >= b)) && a > b
True
True
False
False
Else
General Example:
If Structures
Ex:
Output:
a is greater than 3
This part is skipped because the previous condition was satisfied
Applications
Animation
Challenge Problem
Write a program that lists the numbers from 1 to 100, but: