如果 Else If Else Control
if (i < 2) {
System.out.println("i is less than 2");
} else if (i > 2) {
System.out.println("i is more than 2");
} else {
System.out.println("i is not less than 2, and not more than 2");
}
if 块仅在 i 为 1 或更小时运行。
仅当前面的所有条件(在之前的 else if 构造中,以及父 if 构造中)已经测试到 false 时,才检查 else if 条件。在此示例中,仅当 i 大于或等于 2 时才会检查 else if 条件。
如果它的结果是 true,则运行它的块,并且将跳过它之后的任何 else if 和 else 构造。
如果 if 和 else if 条件都没有通过 true 测试,那么最后将运行 else 块。