The else and else if Statements - C++ Statement

C++ examples for Statement:if

Description

The else and else if Statements

Demo Code

#include <iostream> 
  
using namespace std; 
  
int main(int argc, const char * argv[]) 
{ 
        if (false) 
        { // w w  w .  j  a  v a2  s .c o m
                cout << "Print This When True!"; 
        } 
        else 
        { 
                cout << "Print This When False!"; 
        } 
        return 0; 
} 
  

Result

The else if Statement

Demo Code

#include <iostream> 
  
using namespace std; 
  
int main(int argc, const char * argv[]) 
{ 
        if (false) 
        { //from w w w  .  ja  v a  2 s  .co  m
                cout << "Print This When True!"; 
        } 
        else if (true) 
        { 
                cout << "Print This When Else If Is True!"; 
        } 
        else 
        { 
                cout << "Print This If All False!"; 
        } 
      
        return 0; 
}

Result


Related Tutorials