C++ Else If

C++ Else If Statement Explanation

if (condition1) {
    // code block 1
} else if (condition2) {
    // code block 2
} else {
    // code block 3
}
  • The if statement checks condition1, and if it's true, code block 1 is executed.
  • If condition1 is false, the else if statement checks condition2, and if it's true, code block 2 is executed.
  • If both condition1 and condition2 are false, code block 3 is executed.