I am still getting difficulty in understanding the difference between OR and short-circuit OR Here is the code
package if_else_if;
public class if_Else_if {
public static void main(String[] args) {
// TODO Auto-generated method stub
int month = 4;
String season;
if(month == 12 || month == 1 || month == 2)
season = "Winter";
else if(month == 3 || month == 4 || month == 5)
season = "Spring";
else if (month == 6 || month == 7 || month == 8)
season = "Summer";
else if (month == 9 || month == 10 || month == 11)
season = "Autumn";
else
season = "Bogus month";
System.out.println("April is a " + season + " month");
}
}
If I simply put 'OR' in place of 'short circuit OR'. I get the same answer. Is it the execution time that makes the difference. As when we use 'OR', it evaluates all the conditions whereas 'Short circuit OR' skips the subsequent conditions after getting 'month == 4'