What is if else statement?
The if-else statement used to executes a certain block of code based on the state of variables. In simple words whenever we need to execute a set of statements based on some condition then we use control flow statements.
See the flow diagram that checks if the user is eligible to vote for its leader or not –
From the above flow-diagram, we can clearly see, if the user’s age is greater than or equal to 18 than he/she is eligible to vote otherwise not. Likewise, we can use if-else statements if different ways to control the flow of the program.
Types of if-else
There are four different types of if-else available in Java –