Chapter 3: MCQs on Control Structures in C++ | C++ Programming

Control structures are fundamental in programming as they control the flow of execution based on certain conditions. This chapter covers key control structures like conditional statements, looping constructs, and loop control mechanisms. Here are 30 MCQs on control structures in Java.


Conditional Statements

  1. Which of the following is a valid conditional statement in Java? a) if-else
    b) for-else
    c) loop-else
    d) while-else
  2. What does the “if” statement do in Java? a) Repeats a block of code
    b) Executes a block of code if the condition is true
    c) Skips a block of code
    d) Exits a block of code
  3. How does an “else” statement function in Java? a) It executes only if the preceding “if” condition is false
    b) It executes if the preceding condition is true
    c) It is used for loop control
    d) It terminates the program
  4. What is the purpose of the “else if” statement in Java? a) To check for multiple conditions after an initial “if” condition
    b) To break out of the loop
    c) To terminate the program
    d) To execute the block of code without a condition
  5. What is the output if the condition in an “if” statement is false? a) It will skip the code inside the block
    b) It will execute the code inside the block
    c) It will jump to the next “if” statement
    d) It will print an error

Switch Statement

  1. Which of the following is true about the “switch” statement in Java? a) It only works with integers
    b) It can handle multiple conditions based on a single variable
    c) It allows looping through values
    d) It can only compare strings
  2. What is required in each case statement of a “switch” block? a) A “return” statement
    b) A variable to compare against
    c) A break statement
    d) A constant expression
  3. How does the “break” statement work inside a switch case? a) It stops the switch and continues the execution after the switch block
    b) It continues with the next case
    c) It returns the value to the calling function
    d) It throws an exception
  4. What will happen if a “switch” statement does not have a “break” statement? a) It will throw a compile-time error
    b) It will execute all subsequent cases until it finds a “break”
    c) It will stop after the first case
    d) It will skip all cases
  5. What types of variables can be used in a “switch” statement? a) Only integers
    b) Only strings
    c) Any data type
    d) Integers, characters, and enumerated types

Looping Statements

  1. What is the purpose of a “for” loop in Java? a) To repeat a block of code a specific number of times
    b) To execute a block of code based on a condition
    c) To handle user input
    d) To jump between multiple blocks of code
  2. Which of the following is the correct syntax for a “for” loop? a) for (int i=0; i<10; i++) { }
    b) for (int i=0; i<=10; i–) { }
    c) for int i=0 to 10 { }
    d) for (i=0; i<10; i++) { }
  3. What does the “while” loop do in Java? a) Loops a specific number of times
    b) Loops as long as the condition is true
    c) Loops until a “break” statement is encountered
    d) Loops until a condition becomes false
  4. Which statement is used to exit a “while” loop prematurely? a) continue
    b) break
    c) return
    d) exit
  5. What is the difference between a “for” loop and a “while” loop in Java? a) “for” loops execute only when a condition is true, while “while” loops run until a condition becomes true
    b) “for” loops are used for indefinite looping, while “while” loops are used for definite looping
    c) “for” loops have a specified number of iterations, while “while” loops do not
    d) “while” loops are more efficient than “for” loops

do-while Loop

  1. How does a “do-while” loop differ from a “while” loop in Java? a) A “do-while” loop runs at least once, even if the condition is false
    b) A “do-while” loop runs only when the condition is true
    c) A “do-while” loop requires an explicit “break” statement
    d) A “do-while” loop can only execute once
  2. What is the correct syntax for a “do-while” loop? a) do { } while (condition);
    b) do { while (condition) }
    c) do while { condition }
    d) do (condition) while { }
  3. What happens if the condition in a “do-while” loop is false? a) The loop is skipped entirely
    b) The loop runs at least once before checking the condition
    c) The loop runs infinitely
    d) The loop stops immediately without executing
  4. Can a “do-while” loop be used in place of a “while” loop? a) Yes, if you want to ensure the loop executes at least once
    b) No, because “while” loops cannot execute the code inside the loop
    c) Yes, if you want the loop to run indefinitely
    d) No, because “do-while” loops do not work with conditions
  5. Which of the following is an advantage of using a “do-while” loop? a) It guarantees that the loop will run at least once, regardless of the condition
    b) It provides better performance than other loops
    c) It always executes a fixed number of times
    d) It simplifies nested loops

Break and Continue

  1. What is the purpose of the “break” statement in Java loops? a) It skips the current iteration and continues with the next one
    b) It exits the loop entirely and continues execution after the loop
    c) It forces the loop to run indefinitely
    d) It pauses the loop until the condition is true
  2. Which statement is used to skip the current iteration of a loop in Java? a) continue
    b) break
    c) exit
    d) stop
  3. In which type of loops can the “continue” statement be used? a) Only “for” loops
    b) Only “while” loops
    c) In all loop types (“for”, “while”, “do-while”)
    d) Only in “do-while” loops
  4. What happens when “continue” is used inside a loop? a) The loop is completely terminated
    b) The loop moves to the next iteration without executing remaining statements
    c) The loop runs indefinitely
    d) The loop executes the remaining code in the current iteration
  5. Which statement will terminate a “while” loop and continue execution after the loop? a) return
    b) break
    c) continue
    d) exit

Nested Loops

  1. What is a “nested loop” in Java? a) A loop that runs infinitely
    b) A loop inside another loop
    c) A loop that skips over elements
    d) A loop that controls the flow of execution
  2. How can a “for” loop be nested inside a “while” loop in Java? a) by simply writing one inside the other
    b) by using a “continue” statement
    c) by using a “break” statement
    d) Nested loops are not possible in Java
  3. What is the maximum number of loops that can be nested in Java? a) 1
    b) 2
    c) There is no strict limit
    d) 5
  4. What is the primary concern when using nested loops? a) Efficiency and performance issues
    b) Simplicity of code
    c) It can only be done in “while” loops
    d) Managing input/output operations
  5. How does the performance of nested loops compare to single loops? a) Nested loops have a higher time complexity and may be less efficient
    b) Nested loops perform better than single loops
    c) Nested loops always execute faster than single loops
    d) There is no difference in performance

Answers

QnoAnswer
1a) if-else
2b) Executes a block of code if the condition is true
3a) It executes only if the preceding “if” condition is false
4a) To check for multiple conditions after an initial “if” condition
5a) It will skip the code inside the block
6b) It can handle multiple conditions based on a single variable
7b) A variable to compare against
8a) It stops the switch and continues the execution after the switch block
9b) It will execute all subsequent cases until it finds a “break”
10d) Integers, characters, and enumerated types
11a) To repeat a block of code a specific number of times
12a) for (int i=0; i<10; i++) { }
13b) Loops as long as the condition is true
14b) break
15c) “for” loops have a specified number of iterations, while “while” loops do not
16a) A “do-while” loop runs at least once, even if the condition is false
17a) do { } while (condition);
18b) The loop runs at least once before checking the condition
19a) Yes, if you want to ensure the loop executes at least once
20a) It guarantees that the loop will run at least once, regardless of the condition
21b) It exits the loop entirely and continues execution after the loop
22a) continue
23c) In all loop types (“for”, “while”, “do-while”)
24b) The loop moves to the next iteration without executing remaining statements
25b) break
26b) A loop inside another loop
27a) by simply writing one inside the other
28c) There is no strict limit
29a) Efficiency and performance issues
30a) Nested loops have a higher time complexity and may be less efficient

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