CBSE Class 11 Computer Science Question 108 of 161

Flow of Control — Question 17

Back to all questions
17
Question

Question 11c

Predict the output of the following code fragments:

keepgoing = True        
x=100                   
while keepgoing :       
    print (x)
    x = x - 10 
    if x < 50 :
       keepgoing = False

Answer

Output
100
90
80
70
60
50
Explanation

Inside while loop, the line x = x - 10 is decreasing x by 10 so after 5 iterations of while loop x will become 40. When x becomes 40, the condition if x < 50 becomes true so keepgoing is set to False due to which the while loop stops iterating.

Answer