I have several independent if conditions, and in each condition I will evaluate the value of the boolean variable to both true and false.
if the value of boolean variable gets false in the first if condition, then how can I skip the rest of the conditions.
private static boolean isRecommended(Fruit fruit) { boolean isRecommended = true; if(fruit.weight > 2){ isRecommended = false; } if(!"red".equals(fruit.color)){ isRecommended = false; } if(!"sweet".equals(fruit.taste)){ isRecommended = false; } if(!fruit.isPerishable){ isRecommended = false; } return isRecommended; }
if the first condition if () is satisfied, is it possible to return the value. I know that in loops we can use the continue keyword to skip the rest of the loop. How can we achieve something like this here.
Update:
i does not mean exactly in the first condition if (), if any of the conditions if () is satisfied, then the best way to skip the remaining conditions, such as continue, is executed in a loop
source share