Page 49 - Modular_V1.1_Flipbook
P. 49
Recap
Conditional statements are used to test conditions and decide the flow of a program on the
basis of result of the conditions.
The if statement selects and executes the statement(s) based on a given condition.
The if…else statement is used to evaluates one block of statements out of two.
C++ allows you to use the if statement inside another if statement.
The if…else…if ladder is another type of if statement that helps us to test multiple conditions.
The switch statement comes as a handy replacement of a long series of if…else…if statement.
Exercise
A. Tick (3) the correct option.
1. What will be the output of the following code?
if(True)
cout<<“Hello”;
else
cout<<“Hi”;
a. Hello c. Hello Hi
b. Hi d. Nothing will print
2. …………………… statements are also known as decision making statements.
a. Assignment c. Addition
b. Conditional d. None of these
3. What will be the output of the following code?
void main()
{
int a=0;
a = 5<2 ? 4 : 3;
cout<<a;
}
a. 3 c. 5
b. 4 d. 12
4. Which of the following statements is correct?
a. else if is necessary to use with if statement
b. else is compulsory to use with if statement
c. else is optional with if statement
d. none of the above
Conditional Statements 47

