mardi 9 janvier 2018

What's the difference between using an else if statement and just creating a new if statement? [duplicate]

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