MCQs on Control Flow Statements | Dart

Control flow statements are essential for programming logic. This set of 30 MCQs covers if-else, switch-case, loops (for, while, do-while), and break/continue statements in Dart.


Chapter 3: Control Flow Statements in Dart – MCQs

1. If-Else Statements (8 Questions)

  1. What is the correct syntax for an if statement in Dart?
    a) if condition {}
    b) if (condition) {}
    c) if condition:
    d) if [condition] {}
  2. Which of the following is true about the if-else statement in Dart?
    a) The else block is mandatory.
    b) The if block must have curly braces.
    c) It allows conditional branching.
    d) Nested if statements are not allowed.
  3. What will the following code output?
    int x = 10; if (x > 5) print("Greater"); else print("Smaller");
    a) Greater
    b) Smaller
    c) Error
    d) None of the above
  4. In Dart, how can you write a single-line conditional if statement?
    a) if condition then action;
    b) if condition: action;
    c) if (condition) action;
    d) if {condition} action;
  5. What will happen if the condition in an if statement evaluates to false?
    a) The code block will execute.
    b) The program will crash.
    c) The program skips the block.
    d) The program enters an infinite loop.
  6. How do you check multiple conditions in an if statement?
    a) Use && or || operators.
    b) Use == only.
    c) Write multiple if blocks.
    d) Combine using a switch-case.
  7. What is the output of this code?
    int x = 8; if (x < 5) print("Less"); else if (x == 8) print("Equal"); else print("Greater");
    a) Less
    b) Equal
    c) Greater
    d) Error
  8. Which of the following is an incorrect if-else statement in Dart?
    a) if (true) { print("Yes"); }
    b) if (false) { print("No"); } else { print("Yes"); }
    c) if (true) { print("True"); } else if (false) { print("False"); }
    d) if (true) print("True") else print("False");

2. Switch-Case (7 Questions)

  1. Which keyword is used to exit a case block in Dart?
    a) break
    b) exit
    c) stop
    d) continue
  2. What happens if a break statement is missing in a Dart switch-case block?
    a) It causes a syntax error.
    b) It executes the next case(s).
    c) It skips all cases.
    d) It exits the switch block.
  3. Which of the following is a valid switch-case syntax in Dart?
    a) switch x { case 1: ... }
    b) switch (x) { case 1: ... }
    c) switch [x] { case 1: ... }
    d) switch<x> { case 1: ... }
  4. What is the role of the default case in a switch statement?
    a) Executes if no case matches.
    b) Terminates the program.
    c) Acts as the first case.
    d) Forces program execution to stop.
  5. Can multiple cases in a Dart switch statement execute the same code?
    a) Yes, by omitting break.
    b) No, each case must be unique.
    c) Yes, by chaining them together.
    d) No, Dart does not allow this.
  6. Which data types can be used in Dart switch statements?
    a) int and String
    b) bool
    c) double
    d) All data types
  7. What will this code print?
    var grade = 'A'; switch (grade) { case 'A': print("Excellent"); break; case 'B': print("Good"); break; default: print("Needs Improvement"); }
    a) Excellent
    b) Good
    c) Needs Improvement
    d) Error

3. Loops (For, While, Do-While) (10 Questions)

  1. How does a for loop in Dart begin?
    a) for (var i = 0; i < n; i++)
    b) for i in range(n)
    c) for i = 0 until n
    d) loop for (i in n)
  2. Which of these is a valid while loop syntax in Dart?
    a) while condition { ... }
    b) while (condition) { ... }
    c) while [condition] { ... }
    d) while condition do { ... }
  3. What is the primary difference between while and do-while loops?
    a) do-while executes at least once.
    b) while executes at least once.
    c) while is faster.
    d) There is no difference.
  4. How can you iterate over a list using a for loop in Dart?
    a) for (var item in list)
    b) for each (item in list)
    c) foreach (var item in list)
    d) loop (list as item)
  5. What does this code output?
    for (int i = 0; i < 3; i++) { print(i); }
    a) 0 1 2
    b) 1 2 3
    c) 0 1 2 3
    d) Error
  6. What will this code snippet do?
    int x = 10; do { print(x); x--; } while (x > 0);
    a) Prints numbers 10 to 1
    b) Prints numbers 9 to 0
    c) Prints numbers 10 to 0
    d) Error
  7. Can a for loop contain another for loop in Dart?
    a) Yes, it is called nesting.
    b) No, it causes a runtime error.
    c) No, it is syntactically invalid.
    d) Yes, but only with while loops.
  8. What will this while loop do?
    int i = 0; while (i < 5) { print(i); i++; }
    a) Print 0 to 4
    b) Print 1 to 5
    c) Print 0 to 5
    d) Error
  9. What is the correct keyword to exit a loop in Dart?
    a) continue
    b) break
    c) stop
    d) exit
  10. What is the result of this loop?dartCopy codeint i = 5; while (i > 0) { i--; if (i == 2) break; print(i); } a) 4 3 2
    b) 4 3
    c) 5 4 3 2
    d) 5 4 3

4. Break and Continue (5 Questions)

  1. What does the break statement do in Dart loops?
    a) Exits the loop immediately.
    b) Skips the current iteration.
    c) Ends the program.
    d) Restarts the loop.
  2. What does the continue statement do in Dart?
    a) Ends the loop immediately.
    b) Skips the current iteration.
    c) Restarts the loop.
    d) Exits the program.
  3. Where can the break statement be used?
    a) Loops only
    b) Switch statements only
    c) Both loops and switch statements
    d) Neither
  4. How can you terminate a for loop when a condition is met?
    a) Use break.
    b) Use continue.
    c) Use exit.
    d) Use terminate.
  5. Which of these causes an infinite loop?
    a) while (true) { }
    b) for ( ; ; ) { }
    c) do { } while (true)
    d) All of the above

Here are the answers for the 30 MCQs based on Control Flow Statements in Dart:

QnoAnswer
1b) if (condition) {}
2c) It allows conditional branching.
3a) Greater
4c) if (condition) action;
5c) The program skips the block.
6a) Use && or `
7b) Equal
8d) if (true) print("True") else print("False");
9a) break
10b) It executes the next case(s).
11b) switch (x) { case 1: ... }
12a) Executes if no case matches.
13c) Yes, by chaining them together.
14d) All data types
15a) Excellent
16a) for (var i = 0; i < n; i++)
17b) while (condition) { ... }
18a) do-while executes at least once.
19a) for (var item in list)
20a) 0 1 2
21a) Prints numbers 10 to 1
22a) Yes, it is called nesting.
23a) Print 0 to 4
24b) break
25b) 4 3
26a) Exits the loop immediately.
27b) Skips the current iteration.
28c) Both loops and switch statements
29a) Use break.
30d) All of the above

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