ICSE Class 10 Computer Applications Question 7 of 30

Solved 2023 Question Paper ICSE Class 10 Computer Applications — Question 7

Back to all questions
7
Question

Question 1(vii)

State the type of loop in the given program segment:

for (int i = 5; i != 0; i -= 2)
    System.out.println(i);
  1. finite
  2. infinite
  3. null
  4. fixed
Answer

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:

IterationValue of iRemark
15Initial value of i = 5
23i = 5 - 2 = 3
31i = 3 - 2 = 1
4-1i = 1 - 2 = -1
5-3i = -1 - 2 = -3 and so on...

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