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 :: c++ if else example 
Cpp :: c++ write string 
Cpp :: C++ Vector Operation Access Elements 
Cpp :: educative 
Cpp :: c++ class methods 
Cpp :: C++ vector structure 
Cpp :: stl map remove item 
Cpp :: count c++ 
Cpp :: find maximum sum of circular subarray 
Cpp :: c language all keywords in string 
Cpp :: heap allocated array in c ++ 
Cpp :: dynamic memory in c++ 
Cpp :: if else c++ 
Cpp :: max and min function in c++ 
Cpp :: An Array declaration by initializing elements in C++ 
Cpp :: c++ shared pointer operator bool 
Cpp :: lcm in c++ 
Cpp :: recherche recursive le max dans une liste 
Cpp :: Madiar loh 
Cpp :: uint16_t in c++ 
Cpp :: c++ error missing terminating character 
Cpp :: reverse the number codechef solution in c++ 
Cpp :: input time from console C++ 
Cpp :: progress bar custom color c++ buider 
Cpp :: default parameter c++ a field 
Cpp :: find with hash set 
Cpp :: sfml time set 
Cpp :: omp multiple reductions 
Cpp :: convert java to c++ 
Cpp :: C++ Vector Initialization method 01 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =