The if-else-if ladder in Java is a decision-making construct used to evaluate multiple conditions sequentially. It allows a program to execute only one block of code from several possible options based on the first condition that evaluates to true. If none, an optional else block is executed.
Conditions are checked top to bottom
Only one block executes
Execution stops as soon as a true condition is found
Example:
Output
Grade B
Explanation:
Conditions are checked from top to bottom until a true condition is found.
Since marks is 78, the condition marks >= 75 is true, so Grade B is printed.
Once a true condition executes, the remaining conditions are skipped.
Syntax
if (condition1) { // executes if condition1 is true } else if (condition2) { // executes if condition2 is true } else if (condition3) { // executes if condition3 is true } else { // executes if none of the above conditions are true }