We read your photo as:

Which loop is most compact for counter-controlled iteration.

Computer Science

ScanSolve AI Answer

Answer

C

The question asks which loop is most compact for counter-controlled iteration.

  • A. Do-while: A do-while loop executes its body at least once, then checks the condition. For counter-controlled iteration, the counter initialization, condition, and increment/decrement are typically spread across multiple lines (before the loop, in the while condition, and inside the loop body).
  • B. While: A while loop checks its condition before executing its body. Similar to do-while, for counter-controlled iteration, the counter initialization, condition, and increment/decrement are usually on separate lines.
  • C. For: A for loop is specifically designed for counter-controlled iteration. It consolidates the initialization of the counter, the condition for continuation, and the update (increment/decrement) of the counter into a single, compact line in the loop header. This makes it the most concise and readable option for this purpose.
  • D. Switch: A switch statement is a selection control structure, not a loop. It is used to execute different blocks of code based on the value of a variable, not for repeated execution.

Therefore, the for loop is the most compact for counter-controlled iteration.

The correct option is C.
C) For

Was this helpful?

Try one yourself

A new problem that tests the same skill.

Still stuck on this one?

Ask a follow-up, and the answer starts from this question.

Got a different question?Ask your own question
Handwritten step-by-step solution preview

Handwritten Step-by-Step Solution

Get this as a handwritten image on WhatsApp — like a tutor wrote it for you.

Try on WhatsApp