3.2.1 - For Loop, While Loop and Do-while Loop.
1. What is the purpose of a loop in programming?
Correct Answer: (B) To execute a set of instructions multiple times
2. Which of the following loops is a pre-tested loop?
Correct Answer: (D) Both A and B
3. What is the correct syntax for a for loop in C?
Correct Answer: (B) for(initialization; condition; increment/decrement)
4. What happens when the condition in a while loop becomes false?
Correct Answer: (B) The loop terminates
5. In a do-while loop, when is the condition checked?
Correct Answer: (B) After the loop executes
6. What happens if the loop control variable is not incremented or decremented in a for loop?
Correct Answer: (B) The loop will become an infinite loop
7. Which loop guarantees that the loop body will execute at least once, even if the condition is false initially?
Correct Answer: (C) Do-while loop
8. Which of the following loops is best suited for a situation where the number of iterations is not known in advance?
Correct Answer: (B) While loop
9. Which statement is true about nested loops?
Correct Answer: (B) Any number of loops can be nested within another loop
10. What happens if the condition of a for loop is omitted?
Correct Answer: (B) The loop will execute infinitely
11. Which loop type is used when a condition needs to be tested after executing the loop body?
Correct Answer: (C) Do-while loop
12. What will happen in the following code?
int i = 10; while(i > 5) { printf("%d", i); }
Correct Answer: (A) The loop will execute infinitely
13. What is the default step value in a for loop if it is not explicitly specified?
Correct Answer: (B) 1
14. Which of the following conditions can result in an infinite loop?
Correct Answer: (D) All of the above
15. What should be established at the outset of a loop in order to prevent infinite execution?
Correct Answer: (C) Initialization, condition, and step value
16. What is the primary difference between a while loop and a for loop?
Correct Answer: (C) A for loop is typically used when the number of iterations is known
17. What is the condition for a loop to stop executing?
Correct Answer: (C) The loop condition becomes false