C++ if-elseLast Updated : 10 Jan 2026 Programming languages rely on conditional statements to implement execution control through specific code blocks dependent on conditions. C++ programming offers the if-else statement because it is a fundamental conditional construct for making decisions. The if statement checks a provided condition to choose between running different sections of code based on truth or false. C++ includes multiple iterations of the if statement to manage different program requirements efficiently. In C++ programming, an if statement is used to test the condition. Types of if Statements in C++There are various types of if statements in C++. Some of them are as follows:
Each decision-making structure within C++ provides unique functionalities that boost programming flexibility because they perform distinct tasks. 1. C++ if Statement:The most basic form of conditional statement in C++ requires only an if statement. The C++ if statement tests the condition. It is executed if the condition is true. When the condition proves false, the program omits the subsequent if block. Syntax: It has the following syntax: Flowchart of if statement ![]() C++ If Example: Let us take an example to illustrate the if statement in C++. ExampleCompile and RunOutput: It is even number Explanation:
2. C++ If-else Statement:The C++ if-else statement also tests the condition. It executes if the block if condition is true otherwise else block is executed. Syntax: It has the following syntax: Flowchart of if-else statement ![]() C++ If-else Example: Let us take an example to illustrate the if-else statement in C++. ExampleCompile and RunOutput: It is odd number Explanation:
3. C++ if-else-if ladder Statement:The C++ if-else-if ladder statement executes one condition from multiple statements. Multiple cases can be handled through an if-else if conditional sequence in this structure. Syntax: It has the following syntax: Flowchart of if-else-if ladder statement ![]() C++ if-else-if ladder Example: Let us take an example to illustrate the if-else-if ladder statement in C++. ExampleCompile and RunOutput: Enter a number to check grade:66 C Grade Output: Enter a number to check grade:-2 wrong number Explanation:
4. Nested if Statement:The if statement structure includes another if statement within its body. Consecutive levels of conditional checks require the utilization of this statement. Syntax: It has the following syntax: Flowchart of nested if statement ![]() Nested if Example: Let us take an example to illustrate the nested if statement in C++. ExampleCompile and RunOutput: Enter your age: 18 Do you have an ID? (1 for Yes, 0 for No): 1 You are allowed to enter. Explanation:
ConclusionIn conclusion, C++ programs use if statements as basic decision tools, which trigger conditional responses based on different circumstances. Different variations consist of simple if alongside if-else, if-else-if ladder, and nested if along with the ternary operator to adapt to numerous conditions. A programmer's selection of if statement type determines both the readability and efficiency as well as the maintainability of their code. Next TopicC++ switch |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India



