Search
 
SCRIPT & CODE EXAMPLE
 

CPP

C++ Nested if...else

// outer if statement
if (condition1) {

  // statements

  // inner if statement
  if (condition2) {
    // statements
  }
}
Comment

c++ nested if else example

// C++ program to illustrate nested-if statement
#include <iostream>
using namespace std;
 
int main()
{
    int i = 10;
 
    if (i == 10)
    {
        // First if statement
        if (i < 15)
           cout<<"i is smaller than 15
";
 
        // Nested - if statement
        // Will only be executed if statement above
        // is true
        if (i < 12)
            cout<<"i is smaller than 12 too
";
        else
            cout<<"i is greater than 15";
    }
 
    return 0;
}
Comment

C++ Nested if

// C++ program to find if an integer is positive, negative or zero
// using nested if statements

#include <iostream>
using namespace std;

int main() {

  int num;
    
  cout << "Enter an integer: ";  
   cin >> num;    

  // outer if condition
  if (num != 0) {
        
    // inner if condition
    if (num > 0) {
      cout << "The number is positive." << endl;
    }
    // inner else condition
    else {
      cout << "The number is negative." << endl;
    }  
  }
  // outer else condition
  else {
    cout << "The number is 0 and it is neither positive nor negative." << endl;
  }

  cout << "This line is always printed." << endl;

  return 0;
}
Comment

c++ nested if

if (condition1) 
{
   // Executes when condition1 is true
   if (condition2) 
   {
      // Executes when condition2 is true
   }
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: inheritance in c++ 
Cpp :: convert all strings in vector to lowercase or uppercase c++ 
Cpp :: grep xargs sed 
Cpp :: c ++ split_string 
Cpp :: search by value in map in stl/cpp 
Cpp :: break statement in c++ program 
Cpp :: calculator in cpp 
Cpp :: c++ data types 
Cpp :: How to split a string by Specific Delimiter in C/C++ 
Cpp :: selection sort c++ 
Cpp :: range based for loop c++ 
Cpp :: uparam(ref) 
Cpp :: C++ wchar_t 
Cpp :: sweetalert2 email and password 
Cpp :: for statement c++ 
Cpp :: what is a variable in cpp 
Cpp :: balanced parentheses 
Cpp :: age in days in c++ 
Cpp :: cout stack in c++ 
Cpp :: balanced brackets in c++ 
Cpp :: c++ swap function 
Cpp :: c++ write string 
Cpp :: c++ program to find gcd of 3 numbers 
Cpp :: and c++ 
Cpp :: C++ Vector Operation Change Elements 
Cpp :: c++ last element of vector 
Cpp :: c++ segmentation fault 
Cpp :: fname from FString 
Cpp :: prefix using stack 
Cpp :: uint16_t in c++ 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =