MCQ Practice Single Best Answer Topic: ICSE Computer Application - Class X - 2023 PYQ

Q State the type of loop in the given program segment:

for (int i = 5; i != 0; i -= 2)
    System.out.println(i);

Question ID
#23949
Subchapter
ICSE Computer Application - Class X - 2023 PYQ
Action
Choose one option below

Choose Your Answer

Click an option to check whether your answer is correct.

  • A finite
  • B infinite
  • C null
  • D fixed
Correct Answer: B

Explanation

infinite

Reason — The given loop is an example of infinite loop as for each consecutive iteration of for loop, the value of i will be updates as follows:

Iteration Value of i Remark
1 5 Initial value of i = 5
2 3 i = 5 - 2 = 3
3 1 i = 3 - 2 = 1
4 -1 i = 1 - 2 = -1
5 -3 i = -1 - 2 = -3 and so on...

Since i will never be '0', the loop will execute infinitely.

Share This Question

Share this MCQ with your friends or study group.