Single Choice Easy

QState the type of loop in the given program segment:

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

ID: #23949 ICSE Computer Application - Class X - 2023 PYQ 90 views
Question Info
#23949Q ID
EasyDifficulty
ICSE Computer Application - Class X - 2023 PYQTopic

Choose the Best Option

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

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

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

Challenge a friend or share with your study group.