Java Basics - Control Flow and Conditionals 2
Logical Operators
There are three main logical operators:
AND &&
For example: 3<5 && 2> 15 results in false
AND needs both of its conditions to be true to evaluate to true.
OR ||
For example:3< 5 || 2>15 results to true
OR only needs one of its conditions to be true to evaluate to true.
NOT !
For example:!(3<5) results to false
AND evaluates before OR.
This means that an if statement is within an if statement.
There are three main logical operators:
AND &&
For example: 3<5 && 2> 15 results in false
AND needs both of its conditions to be true to evaluate to true.
OR ||
For example:3< 5 || 2>15 results to true
OR only needs one of its conditions to be true to evaluate to true.
NOT !
For example:!(3<5) results to false
The NOT turns a boolean value into its opposite value
The order of operations is:
1. Parentheses ()
2. NOT !
3. AND &&
4. OR ||
The order of operations is:
1. Parentheses ()
2. NOT !
3. AND &&
4. OR ||
More on Logical Operators
AND evaluates before OR.
So false&&true||true evaluates to true
while false&&(true||true) evaluates to false
_______________________________________________
Nested IF Statements
This means that an if statement is within an if statement.
if(condition1 ==true){
if(condition2 == true) {} //this is the nested if statement.
}
Comments
Post a Comment