Selection Statements in C ++
In C++, selection statements are used to control the flow of execution based on certain conditions. Here's a breakdown of the most common ones: 1. if statement * Basic Structure: if (condition) { // Code to be executed if the condition is true } * Example: int age = 25; if (age >= 18) { cout << "You are an adult." << endl; } * if...else statement: if (condition) { // Code to be executed if the condition is true } else { // Code to be executed if the condition is false } * Example: int number = 10; if (number % 2 == 0) { cout << "The number is even." << endl; } else { cout << "The number is odd." << endl; } * if...else if...else statement: if (condition1) { // Code to be executed if condition1 is true } else if (condition2) { // Code to be executed if condition1 is false and condition2 is true } else { ...