Computer Science, asked by rajakumar7011, 1 year ago

Explain the if else if ladder?

Answers

Answered by Arjunaksd
1
there is no sense of this question
Answered by alia2000chadda
2

The conditional expressions are evaluated from the top downward. As soon as a true condition is found, the statement associated with it is executed, and the rest of the ladder is bypassed. If non of the conditions is true, then the final else statement will be executed. The final else often acts as a default condition; that is, if all other conditions tests fail, then the last else statement is performed. If there is no final else and all other conditions are false then no action will take place. Example

// Demonstration of if-else-if ladder


#include <iostream.h>

main ( )

{

int x;

cout << "Enter an integer between 1 and 6";

cin >> x;

if(x==1) cout<<"The number is one $\backslash$n";

else if(x==2)cout<<"The number is two $\backslash$n";

else if(x==3)cout<<"The number is three $\backslash$n";

Similar questions