Question 29Asked in DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 1 (9:00 AM)

Which of the following causes an infinite loop?

  1. Afor (int i = 10; i >5; i--) { }
  2. Bdo { } while (0);
  3. Cwhile (1) { }
  4. Dfor (int i = 0; i < 10; i++) { }
Show answerHide answer

Correct answer: (C) while (1) { }

Explanation

while (1) has a condition that is always true (non-zero) and nothing inside the body to break out, so it never ends. The for loops terminate and do { } while (0) runs once.

From DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 1 (9:00 AM)

This is question 29 of DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 1 (9:00 AM). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.