MCQs on Control Flow Statements | C#

Understanding control flow statements like conditional statements, loops, break/continue, and exception handling is essential for writing clean and efficient C# code. This guide will walk you through each concept.


Control Flow Statements in C# – 30 Multiple Choice Questions

1. Conditional Statements (if, if-else, switch)

  1. Which of the following is a valid syntax for the if statement in C#?
    • A) if(condition) { //code }
    • B) if { condition; }
    • C) if (condition) { code } else
    • D) if: condition { code }
  2. What will be the output of the following C# code?csharpCopy codeint x = 5; if (x > 3) { Console.WriteLine("Greater"); } else { Console.WriteLine("Smaller"); }
    • A) Greater
    • B) Smaller
    • C) Error
    • D) Nothing
  3. Which of the following is the correct way to use an if-else statement in C#?
    • A) if (condition) { //block } else { //block }
    • B) if condition { //block } else { }
    • C) if (condition) { } else
    • D) else { } if (condition) { }
  4. What does the switch statement do in C#?
    • A) Executes one block of code out of multiple choices based on an expression
    • B) Loops through all possible cases
    • C) Breaks out of the loop when the condition is met
    • D) Compares two values for equality
  5. In a switch statement, if no case matches, which statement is executed?
    • A) Default
    • B) Else
    • C) Continue
    • D) Break
  6. What is the correct syntax to define a case in a switch statement in C#?
    • A) case value: { //code }
    • B) case value; { //code }
    • C) case value() { //code }
    • D) switch(value) { //cases }
  7. Which statement is used to exit a switch block early in C#?
    • A) Return
    • B) Continue
    • C) Break
    • D) Exit
  8. In C#, how many else statements can you use in an if-else block?
    • A) Only one
    • B) As many as needed
    • C) Zero
    • D) None
  9. What is the purpose of the default keyword in a switch statement?
    • A) To handle unexpected input or cases
    • B) To loop through all cases
    • C) To break out of the switch block
    • D) To compare values
  10. Which of the following will cause an error in a C# switch statement?
    • A) Using break in a case block
    • B) Using if inside a case block
    • C) Omitting a default case
    • D) Using a non-constant value in a case

2. Looping Statements (for, while, do-while, foreach)

  1. Which loop is guaranteed to run at least once in C#?
    • A) for
    • B) while
    • C) do-while
    • D) foreach
  2. Which of the following loops can iterate over a collection in C#?
    • A) for
    • B) foreach
    • C) while
    • D) do-while
  3. What is the syntax for a for loop in C#?
    • A) for (initialization; condition; increment) { }
    • B) for (initialization) { condition } { increment }
    • C) for (condition) { initialization; increment; }
    • D) for { initialization; condition; increment }
  4. How does a while loop in C# work?
    • A) It runs as long as the condition evaluates to true
    • B) It runs until the condition is false
    • C) It executes a fixed number of times
    • D) It runs indefinitely
  5. Which of the following describes the behavior of a do-while loop in C#?
    • A) The condition is evaluated before the loop runs
    • B) The loop runs at least once regardless of the condition
    • C) The loop runs as long as the condition is false
    • D) It executes only if the condition is true initially
  6. What will the following for loop do?csharpCopy codefor (int i = 0; i < 5; i++) { Console.WriteLine(i); }
    • A) Print numbers from 0 to 5
    • B) Print numbers from 1 to 5
    • C) Print numbers from 0 to 4
    • D) Print 5 only
  7. What is the purpose of the foreach loop in C#?
    • A) It is used to loop through arrays or collections
    • B) It is used to execute a block of code a fixed number of times
    • C) It is used to loop while a condition is true
    • D) It loops through elements based on index
  8. Which of the following is NOT a valid loop type in C#?
    • A) for
    • B) foreach
    • C) repeat
    • D) while
  9. How do you exit a loop early in C#?
    • A) exit
    • B) stop
    • C) return
    • D) break
  10. What will be the output of the following code?csharpCopy codeint x = 0; while (x < 3) { Console.WriteLine(x); x++; }
    • A) 0, 1, 2, 3
    • B) 0, 1, 2
    • C) 1, 2, 3
    • D) 0, 1

3. Break and Continue Statements

  1. What is the function of the break statement in C#?
    • A) Exits the loop or switch statement immediately
    • B) Skips the current iteration and continues to the next one
    • C) Ends the program
    • D) Pauses the loop until a condition is met
  2. Which of the following statements is used to skip the rest of the current loop iteration in C#?
    • A) exit
    • B) continue
    • C) pause
    • D) return
  3. Can the break statement be used in a switch statement in C#?
    • A) Yes, to exit the switch case
    • B) No, the return statement must be used
    • C) Yes, to skip the current case
    • D) No, break is not allowed in switch statements
  4. What happens if a continue statement is encountered in a for loop?
    • A) The loop stops and the program exits
    • B) The loop skips the current iteration and continues with the next one
    • C) The loop terminates
    • D) The loop runs indefinitely
  5. How do break and continue differ in their functionality in C#?
    • A) break exits the loop, while continue skips the current iteration
    • B) break skips the iteration, while continue exits the loop
    • C) Both have the same effect
    • D) break exits the program, while continue skips the loop
  6. Which of the following can the break statement be used in?
    • A) Loops only
    • B) Switch statements only
    • C) Loops and switch statements
    • D) Functions
  7. Which of the following will prevent an infinite loop in C#?
    • A) continue inside the loop
    • B) Using break after a certain number of iterations
    • C) Using return inside the loop
    • D) Both B and C
  8. What will the following code do?csharpCopy codefor (int i = 0; i < 5; i++) { if (i == 3) break; Console.WriteLine(i); }
    • A) Prints 0, 1, 2, 3
    • B) Prints 0, 1, 2
    • C) Prints 0, 1, 2, 3, 4
    • D) Prints 3
  9. How do you skip even numbers in a loop using continue?
    • A) Use continue if the number is even
    • B) Use continue if the number is odd
    • C) Use break for even numbers
    • D) Use continue for odd numbers
  10. In which scenario would you most likely use a break statement in a loop?
    • A) When you want to skip an iteration of the loop
    • B) When you want to exit the loop after a certain condition is met
    • C) To pause the loop at a certain point
    • D) To restart the loop

Answer Key

QnoAnswer
1A) if(condition) { //code }
2A) Greater
3A) if (condition) { //block } else { //block }
4A) Executes one block of code out of multiple choices based on an expression
5A) Default
6A) case value: { //code }
7C) Break
8A) Only one
9A) To handle unexpected input or cases
10D) Using a non-constant value in a case
11C) do-while
12B) foreach
13A) for (initialization; condition; increment) { }
14A) It runs as long as the condition evaluates to true
15B) The loop runs at least once regardless of the condition
16C) Print numbers from 0 to 4
17A) It is used to loop through arrays or collections
18C) repeat
19C) break
20B) 0, 1, 2
21A) Exits the loop or switch statement immediately
22B) continue
23A) Yes, to exit the switch case
24B) The loop skips the current iteration and continues with the next one
25A) break exits the loop, while continue skips the current iteration
26C) Loops and switch statements
27D) Both B and C
28B) Prints 0, 1, 2
29A) Use continue if the number is even
30B) When you want to exit the loop after a certain condition is met

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top