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
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
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.
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic