Activity 1.10.1.
if (condition1) { return false; } if (condition2) { return false; } return true;
- We can conjoin the if conditions together using
||
and then we have an if statement that always returns true in some senarios and false in other senarios. So, we can apply rule 2 and directly return the negation of conjoined conditions. (In the next video you will see how) if (condition1) { return false; }
- No, the if statement only returns false.
boolean flag = true; if (condition1 && condition2 || condition3) { return flag; } return false;
- Yes. the if condition returns boolean variable true when the condition evaluates to true and returns false otherwise. So, we can apply rule 2 and directly return the if condition.
To which of the following code blocks can we apply Rule 2?