CBSE Class 12 Computer Science
Question 94 of 105
Python Revision Tour — Question 20
Back to all questionsThe loop is not infinite. To know this without running it we can analyze how n is changed inside the loop in the following way:
n = 2 * n - m
Substituting value of m from m = n - 1,
n = 2 * n - (n - 1)
⇒ n = 2 * n - n + 1
⇒ n = 2n - n + 1
⇒ n = n + 1
Therefore, inside the loop n is incremented by 1 in each iteration. Loop condition is n < 10 and initial value of n is 5. So after 5 iterations, n will become 10 and the loop will terminate.