When you write several if statements, it is possible that more than one of them will be evaluated as true, since the statements are independent of each other.
When you write a single if else-if else-if ... else, only one condition can be evaluated as true (after the first condition that evaluates to true is found, the following else-if conditions are skipped).
You can make several if statements that behave like an if else-if .. else single if each of the condition blocks exits a block that contains if statements (for example, returning from a method or breaking a loop).
For instance:
public void foo (int x) { if (x>5) { ... return; } if (x>7) { ... return; } }
Will have the same behavior as:
public void foo (int x) { if (x>5) { ... } else if (x>7) { ... } }
But without return statements, this will have a different behavior when x> 5 and x> 7 are both true.
source share