if else in c++

if (condition) { // code to be executed if the condition is true } else { // code to be executed if the condition is false }

  • The "if" statement is used to check a condition. If the condition inside the parentheses is true, the code block inside the curly braces after the "if" statement will be executed.
  • If the condition is false, the code block inside the "else" block will be executed.
  • The "else" statement is optional and is used to specify the code that should be executed if the "if" condition is false.