In what sequence the initialization, testing and execution of body is done…

2022

In what sequence the initialization, testing and execution of body is done while using do-while loop?

A. Commenting

B. Execution of the body

C. Initialisation

D. Testing the condition

Choose the correct answer from the following

Answer: D. C,B,DAnswer: The correct sequence is Initialisation, Execution of the body, Testing the condition. Key point: In a do-while loop the body always runs at least once…

  1. A.

    D,B,C

  2. B.

    D,C,B

  3. C.

    C,A,B

  4. D.

    C,B,D

Attempted by 820 students.

Show answer & explanation

Correct answer: D

Answer: The correct sequence is Initialisation, Execution of the body, Testing the condition.

Key point: In a do-while loop the body always runs at least once because the condition is checked after the body executes.

  1. Initialisation: Set up loop control variable(s) before the loop starts.

  2. Execution of the body: The loop body executes first in a do-while construct.

  3. Testing the condition: After the body runs, the loop condition is evaluated; if true, the loop repeats.

Example (pseudocode):

initialise i

do {

// body executes here

} while (condition);

Therefore the correct ordering is: Initialisation, Execution of the body, Testing the condition.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Nta Ugc Net Paper 2

Loading lesson…