Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
838 views
in Review of C++ Programming by (30.5k points)
closed by

Explain conditional statements in detail?

1 Answer

+1 vote
by (30.4k points)
selected by
 
Best answer

1. Simple if: 

The syntax is given below

if(expression) 

statement; 

or 

if(expression)

{

Block of statements 

}

First expression evaluates if it is true then only statement will be executed. 

Eg. if (n>0)

cout<<n<<” is positive”;

2. if else: 

The syntax is given below. 

if (expression)

statement 1;

else

statement 2;

or

if(expression)

{

  statement block 1;

}

Else

{

statement block 2;

}

First expression evaluates if it is true 

statement block 1 will be executed otherwise

statement block 2 will be executed.

Only one block will be executed at a time so it is called branching statement. 

Eg. if (n>0)

cout<<<n<<"is positive”

else

cout<<<n<<"is negative”; 

3. if else if ladder: 

The syntax will be given below 

if (expression 1)

{

statement block 1;

}

else if (expression 2)

{

statement block 2;

}

else if (expression 3)

{

statement block 3;

}

.....

else

{

statement block n;

}

Here first expression 1 will be evaluated if it is true only the statement block 1 will be executed otherwise expression 2 will be executed if it is true only the statement block2 will be executed and soon. If all the expression evaluated is false then only statement block n will be evaluated. 

Eg

If(mark>=90)

cout«<<“Your grade is A+”;

4. conditional operator: 

It is a ternary operator and it is an alternative for if else construct. The syntax is given below. expression 1? expression 2: expression 3; or expression 1? Value if true: value if false; Here expression 1 will be evaluated if it true expression 2 will be executed otherwise expression 3 will be executed. 

Eg. n>0?cout<<n<<"is positive”:cout<<n<<"is negative”; 

5. Switch:

It is a multiple branch statement. Its syntax is given below. 

switch(expression)

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...