A PL/I programmer wants to repeat an instruction 5 times. How can he/she code this ?
-
REPEAT 5 TIMES; instruction; END;
-
DO J=1 TO 5; instruction; END;
-
COUNTER = 1; DO WHILE COUNTER < 5; COUNTER = COUNTER + 1; instruction; END;
-
REPEAT VARYING COUNTER FROM 1 BY 1 UNTIL COUNTER = 5; instruction; END;
To repeat an instruction 5 times in PL/I, the programmer can use a loop construct.
Option A is not a valid PL/I syntax.
Option B is a correct way to repeat an instruction 5 times in PL/I. It uses a DO loop with a loop control variable J that iterates from 1 to 5, executing the instruction each time.
Option C is also a valid way to repeat an instruction 5 times in PL/I, but it uses a WHILE loop instead of a DO loop. It initializes a counter variable to 1 and repeats the instruction while the counter is less than 5.
Option D is also a valid way to repeat an instruction 5 times in PL/I, but it uses a REPEAT loop with a loop control variable COUNTER that iterates from 1 to 5, executing the instruction each time.
Therefore, the correct answer is:
The Answer is: B
In PL/I, repeating a block of code a fixed number of times is done with a DO loop using the TO clause: DO J=1 TO 5; ... END; increments J automatically from 1 through 5, executing the instruction each time. REPEAT is not a PL/I keyword, and the DO WHILE option shown increments the counter before checking against a condition that doesn't guarantee exactly 5 iterations, so it doesn't reliably repeat 5 times as written.