This question already has an answer here:
What's the point in making an else if statement when you could just make another if statement? i.e
With an else statement:
if (x > 1) {
System.out.println("Hello!");
}else if (x < 1) {
System.out.println("Bye!");
}
Without an else statement:
if (x > 1) {
System.out.println("Hello!");
}
if (x < 1) {
System.out.println("Bye!");
}
Both codes give out the same solution, so what's the point typing 'else' when the output is no difference?
Aucun commentaire:
Enregistrer un commentaire