Java OCA OCP Practice Question 852

Question

Which of the following best describes the flow of execution in this for loop if the loop body is run exactly once?

for (A; B; C) { 
       D; 
} 
  • A. A, D, C, B
  • B. A, B, D, C, B
  • C. A, D, C, A, B
  • D. A, B, D, C, A, B


B.

Note

The initializer, which is A, runs first.

Then Java checks the condition, which is B, to see if loop execution should start.

Then the loop body, which is D, runs.

After the loop execution, the updater, which is C, runs.

Then the loop condition, which is B, is checked again.

Therefore, Option B is correct.




PreviousNext

Related