MCQ Single Best Answer Easy

QHow many times will the following do-while loop execute?

int i = 0;
do {
   printf("%d", i);
   i++;
} while(i < 5);

ID: #23094 Do-While Loop in Programming Language 80 views
Question Info
#23094Q ID
EasyDifficulty
Do-While Loop in Programming LanguageTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A 4
  • B 5
  • C 6
  • D Infinite
Correct Answer: Option B

Explanation

The loop will execute 5 times. Initially, the value of i is 0, and since it is a do-while loop, the loop body executes first, printing i and then incrementing it. After each iteration, the condition i < 5 is checked. The loop will run as long as the condition is true, so the loop runs when i is 0, 1, 2, 3, and 4. When i becomes 5, the condition is false, and the loop terminates.

Share This Question

Challenge a friend or share with your study group.