How to Add Multiple Conditions for if Statement in C++? Last Updated : 21 May, 2024 Comments Improve Suggest changes Like Article Like Report In C++, an if statement is used to decide whether a specific block of code should execute, depending on a given condition. It usually evaluate a single expression to check condition. In this article, we will learn how to add multiple conditions as a single expression for an if statement in C++. Multiple Conditions for if Statement in C++To check multiple conditions in an if statement, we can use logical operators within an if statement to evaluate the conditions. The most commonly used logical operators are: logical AND (&&): If we want the code block to execute only if both the given conditions are true, the && operator is used.logical OR (||): If we want the code block to execute even if at least one of the condition is true, then || The operator is used.Syntax to Define if Statement With Multiple Conditionsif ((condition1 && condition2) || condition3) { // Code to execute if both condition1 and condition2 are true // or condition 3 is true}Note: When combining && and || always use parentheses to explicitly define the precedence of operations that makes code more readable and prevents logical errors. C++ Program to Demonstrate the if Statement With Multiple ConditionsThe below program implements the if statement with multiple conditions. C++ // C++ program to implement if statement with multiple // conditions #include <iostream> using namespace std; int main() { // Declare and initialize an integer variable. int val = 50; // Declare and initialize a boolean variable. bool isPossible = true; // Check multiple conditions in a single if statement // i.e. if num is either 50 or 100 and isPossible is // true. if ((val == 50 || val == 100) && isPossible) { cout << "Given Value is either 50 or 100 and it " "is a possible number." << endl; } return 0; } OutputGiven Value is either 50 or 100 and it is a possible number. Time Complexity: O(1)Auxilliary Space: O(1) Note: The expression in which the multiple logical operations are used is evaluated using short circuiting concept which in some cases, reduce the number of condition evaluation. Comment More infoAdvertise with us Next Article How to Add Multiple Conditions for if Statement in C++? B bhushanc2003 Follow Improve Article Tags : C++ Programs C++ CPP-Basics CPP Examples Practice Tags : CPP Similar Reads How to Utilize the goto Statement in C++? The goto statement in C++ is a control flow statement that allows the users to move the control flow from one part to another part of the program. In this article, we will learn how to utilize the goto statement in C++. Utilize the goto Statement in C++In C++, the goto statement transfers the progra 2 min read How to Add Message to Assert in C++ In C++, assert is a debugging tool that allows the users to test assumptions in their code. The standard assert macro provided by <cassert> checks the condition and if the condition is evaluated as false, the assert statement terminates the program and prints an error message on the console al 2 min read How to Take Operator as Input in C++? Operators are symbols that specify some kind of operation. In C++, we sometimes need to take operators as user input mainly to perform mathematical operations. In this article, we will learn how to take operators as user input in C++. Operators as Input in C++To take operators (like +,-,*,/ etc) as 2 min read How to Check if a Vector Contains a Given Element in C++? In C++, a vector is a dynamic array that provides a resizable and efficient way to store elements. Vectors store their elements in contiguous memory locations, similar to arrays, which allows for efficient access and iteration.In this article, we will learn the different methods to check whether the 3 min read Nested switch statement in C++ Switch-case statements: These are a substitute for long if statements that compare a variable to several integral values The switch statement is a multiway branch statement. It provides an easy way to dispatch execution to different parts of code based on the value of the expression.Switch is a cont 2 min read Like