If Else If Else Control

suggest change
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");
}

The if block will only run when i is 1 or less.

The else if condition is checked only if all the conditions before it (in previous else if constructs, and the parent if constructs) have been tested to false. In this example, the else if condition will only be checked if i is greater than or equal to 2.

If its result is true, its block is run, and any else if and else constructs after it will be skipped.

If none of the if and else if conditions have been tested to true, the else block at the end will be run.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Basic Control structures:
* If Else If Else Control
* Break

Table Of Contents
8 Arrays
10 Maps
11 Strings
15 Basic Control structures
25 JAXB
29 Enums
32 Audio
41 Scanner
63 Logging
75 Lists
78 Sets
89 JAX-WS
96 XJC
98 Process
106 Modules
114 Applets
122 JNDI
139 JavaBean
141 Literals
144 Packages
150 JMX
153 JShell
159 Sockets
167 Enum Map
175 Hashtable
177 SortedMap