Recall & Review
beginner
What is the purpose of an
if statement in C++?An
if statement lets the program decide to run some code only if a condition is true. It's like choosing a path based on a yes/no question.Click to reveal answer
beginner
Write the basic syntax of an
if statement in C++.The basic syntax is:<br>
if (condition) {<br> // code to run if condition is true<br>}Click to reveal answer
beginner
What happens if the condition in an
if statement is false?If the condition is false, the code inside the
if block is skipped and the program continues with the next part.Click to reveal answer
beginner
How do you add an alternative action if the
if condition is false?You use an
else block after the if. It runs when the if condition is false.<br>if (condition) {<br> // if true<br>} else {<br> // if false<br>}Click to reveal answer
intermediate
Can you check multiple conditions in C++? How?
Yes, by using
else if blocks between if and else. It checks conditions one by one until one is true.<br>if (cond1) {<br>} else if (cond2) {<br>} else {<br>}Click to reveal answer
What does this code print?<br>
int x = 5;<br>if (x > 3) {<br> std::cout << "Yes";<br>} else {<br> std::cout << "No";<br>}✗ Incorrect
Since 5 is greater than 3, the condition is true, so it prints "Yes".
Which keyword is used to provide an alternative when an
if condition is false?✗ Incorrect
In C++,
else is used to run code when the if condition is false.What will happen if the
if condition is false and there is no else block?✗ Incorrect
If the condition is false and no
else is present, the program skips the if block and continues.How do you check multiple conditions in sequence?
✗ Incorrect
else if lets you check several conditions one after another.Which of these is a valid
if condition in C++?✗ Incorrect
In C++, conditions must be inside parentheses after
if.Explain how an
if statement controls the flow of a program.Think about making choices based on yes/no questions.
You got /4 concepts.
Describe the difference between
if, else if, and else in C++.Imagine checking multiple doors until one opens.
You got /4 concepts.