This quiz is designed to test your understanding of key concepts related to conditional statements in C#, such as the if, else, and else if constructs. You’ll explore how these control flow mechanisms work to direct the execution of code based on specific conditions. Each question will help reinforce your ability to write and understand conditional logic in C#.
1.
What is the final else block in an if … else if … statement used for?
2.
What is the purpose of the final else block in an if … else if construct?
3.
What is meant by 'conditional control flow'?
4.
Can you have multiple else if blocks in an if statement?
5.
What is the primary difference between an if statement and an else if statement?
6.
What happens if none of the conditions in an if … else if … else statement are true?
7.
Which of the following is true about using multiple else if statements?
8.
What is the correct syntax for an if … else if … else construct?
9.
What is the role of boolean expressions in if statements?
10.
Can an if statement be used without an else statement?
11.
What is the output of the following code?
int x = 11;
if (x == 10) {
Console.WriteLine('x is 10');
} else if (x == 9) {
Console.WriteLine('x is 9');
} else {
Console.WriteLine('x is some other number');
}
12.
What is control flow in programming?
13.
What does the else if statement allow in C#?
14.
What is the output of the following code?
int x = 8; if (x > 9) {
Console.WriteLine(‘x is greater than 9!’);
} else {
Console.WriteLine(‘x is less than 9!’);
}
15.
How is an else statement used in C#?
16.
What is the output of the following code?
int x = 10;
if (x > 9) {
Console.WriteLine('x is greater than 9!');
}
17.
When can the braces ({}) be omitted in an if statement?
18.
What is the correct syntax of a basic if statement in C#?
19.
What happens when the boolean expression in an if statement evaluates to false?
20.
What is the primary purpose of an if statement in C#?
21.
What are the two main types of control flow in programming?