Which of the loop executes a block of code at least once? (i) while (ii) for (iii) do...while (iv) for/in
Answers
Answer:
do...while
Explanation:
iii) do while loop
Explanation:
The do...while loop executes a block of code at least once. Option (iii) is the right answer.
Explanation:
In the do...while loop, the do block is encountered first. In the first iteration, the block is considered as an executable set of statements without any constraints to be fulfilled. After the program exits the block of code under do, the while condition is encountered. Now, if the condition is true, the program jumps to the do block and executes the statements under it. The cycle repeats until the condition in the while statement remains true. In case the condition is false, the program jumps out of the loop. Therefore, regardless of the while statement, the block of code under do executes at least once.