Introduction to if else & if else if statements in C++ Programming Language

 if else and if else if proclamations in C++





if else proclamations in C++ Programming Language


It is a two way spreading clarification of explanation. It involves two blocks of explanations each encased inside if block and else block exclusively. If the condition inside on the off chance that proclamation is legitimate, explanations inside accepting block are executed, in any case articulations inside else block are executed. Else block is optional and it very well may be absent in a program.


Sentence structure


if ( given condition )

{

    block of explanations ;

}

else

{

    block of articulations ;

}


Flowchart of if else articulation




Code in C++

#incorporate <iostream>

utilizing namespace sexually transmitted disease ;

int fundamental( ) {

  int t = 25 ;

  if ( t < 8 ) {

    cout << " Great Morning " ;

  } else {

    cout << " Great Night " ;

  }

  return 0 ;

}


Result of above Code


Goodbye


if else if proclamation in C++ Programming Language


It is used when more than one condition is to be checked. A block of explanation is encased inside if, else if and else part. Conditions are checked in each if and else if part. Assuming the condition is substantial, the explanation inside that block are executed. In the event that the condition are not commonly obvious, the explanation inside else block are executed. An if else assuming that proclamation ought to have provided that that block anyway can have as various else if block as required. Else part is discretionary and may accessible or miss.


Language structure


if ( given condition 1 )

{

    block of explanations ;

}

else if ( given condition 2 )

{

    block of proclamations ;

}

else if ( given condition n )

{

    block of proclamations ;

}

else

{

    block of proclamations ;

}


Flowchart of if else if explanation




Code in C++


#include<iostream>

utilizing namespace sexually transmitted disease ;

int fundamental( )

{

    int x = 9 ;

    if( x < 0 )

       cout << " - ve Number " << endl ;

    else if( n > 0 )

      cout << " +ve Number " << endl ;

    else

       cout << " Number = 0 " << endl ;

    return 0 ;

}


Result of above Code


 +ve Number


I genuinely want to believe that You can undoubtedly Comprehend and Realize this Article


Good luck 😇

Post a Comment

0 Comments