15 extra multiple-choice questions for Loops in PHP (12th Standard Computer Applications, Samacheer Kalvi), beyond the ones printed in the textbook — each with the correct option highlighted and a clear, worked explanation. Free to read in English and Tamil.
Q1
What is a control structure that repeatedly executes a block of code until a specific condition is met in PHP?
- A. Function
- B. Class
- C. LoopCorrect
- D. Array
Explanation. In PHP, a loop is a control structure designed to repeatedly execute a block of code until a certain condition is met or for a specific number of times.
Q2
How many primary types of looping structures are supported in PHP as described in the textbook?
- A. Two
- B. Three
- C. FourCorrect
- D. Five
Explanation. PHP supports four main types of loops: the for loop, while loop, do...while loop, and foreach loop.
Q3
Which of the following loops is classified as an exit-check loop in PHP?
- A. for loop
- B. do...while loopCorrect
- C. while loop
- D. foreach loop
Explanation. The do...while loop is called an exit-check loop because the condition is evaluated at the end of each iteration, after the code block has executed.
Q4
In a PHP for loop, which part of the loop syntax is executed exactly once at the very beginning?
- A. Condition
- B. InitializationCorrect
- C. Increment
- D. Decrement
Explanation. The initialization part of a for loop is executed only once at the beginning of the loop to initialize loop variables.
Q5
If the condition of a while loop is false at the very first check, how many times will the code block be executed?
- A. Zero timesCorrect
- B. Exactly once
- C. Infinitely
- D. Until incremented
Explanation. Because a while loop is an entry-check loop, it evaluates the condition before executing the code block. If the condition is false initially, the block is never executed.
Q6
Which PHP loop structure guarantees that the code block will be executed at least once, even if the condition is false from the start?
- A. while loop
- B. for loop
- C. do...while loopCorrect
- D. foreach loop
Explanation. The do...while loop executes the code block first and then evaluates the condition, ensuring at least one execution regardless of the condition's initial truth value.
Q7
What is the primary purpose of the foreach loop in PHP?
- A. To execute code a specific numeric number of times
- B. To check conditions at the exit of a loop
- C. To iterate specifically over the elements of an arrayCorrect
- D. To declare multiple database connections
Explanation. The foreach loop is designed specifically to iterate over elements of an array easily and efficiently.
Q8
In the PHP loop statement foreach (\(employee as \)id => \(name), what does the variable \)id represent?
- A. The value of the current element
- B. The key or index of the current elementCorrect
- C. The total number of elements in the array
- D. The database table name
Explanation. In the key-value syntax of a foreach loop, the variable before the double arrow operator represents the key or index of the array element.
Q9
Which part of a PHP for loop is used to update the loop variable after each iteration?
- A. Initialization
- B. Condition
- C. Increment/decrementCorrect
- D. Code block
Explanation. The increment or decrement part of a for loop is executed after each iteration of the loop and is used to update the variables.
Q10
In a PHP for loop, when is the loop condition evaluated?
- A. Only once at the beginning of the loop
- B. Before each iteration of the loopCorrect
- C. After each iteration of the loop
- D. Only when the loop terminates
Explanation. The condition in a for loop is evaluated before each iteration. If it is true, the block executes; if false, the loop terminates.
Q11
What happens if a while loop's condition always evaluates to true and has no statement to modify the loop variable?
- A. The loop will not compile
- B. The loop will execute exactly once
- C. The loop will become an infinite loopCorrect
- D. The loop will automatically terminate
Explanation. A while loop continues as long as its condition is true. If the condition never becomes false, the loop runs infinitely.
Q12
What is a group of statements designed to be executed together as a single unit in PHP control structures called?
- A. Function name
- B. Array element
- C. Code blockCorrect
- D. Parameter list
Explanation. A block of code, also known as a code block, is a group of statements enclosed in curly braces that are executed together as a single unit.
Q13
To print both the keys and values of an associative array in PHP, which symbol separates the key and value variables in the foreach statement?
- A. ->
- B. =>Correct
- C. ::
- D. .
Explanation. The double arrow operator is used in a PHP foreach loop to separate the key variable from the value variable.
Q14
Besides the for loop, which other looping structure is classified as an entry-check loop in PHP?
- A. do...while loop
- B. while loopCorrect
- C. switch statement
- D. if...else statement
Explanation. Both the for loop and the while loop are classified as entry-check loops in PHP because they evaluate the condition before executing the loop body.
Q15
What is the main difference in the minimum number of iterations between a while loop and a do...while loop in PHP?
- A. The while loop has a minimum of one iteration, while do...while has zero
- B. The while loop has a minimum of zero iterations, while do...while has oneCorrect
- C. Both loops have a minimum of zero iterations
- D. Both loops have a minimum of one iteration
Explanation. A while loop may not execute at all (minimum of 0 iterations) if the condition is false initially, whereas a do...while loop always executes at least once.
Frequently asked questions
How many MCQs are there in Loops in PHP?
This chapter has 15 book-back multiple-choice questions, each with the correct answer and a step-by-step explanation.
Are these 12th Standard Computer Applications MCQs free to practise online?
Yes. Every question, answer and explanation here is free, and you can also take them as a timed practice test.
Where can I find the Loops in PHP book-back answers?
The correct option for each question is highlighted on this page with a worked explanation, plus a quick answer-key summary at the top.