CBSE Class 11 Computer Science Question 119 of 161

Flow of Control — Question 28

Back to all questions
28
Question

Question 11n

Predict the output of the following code fragments:

c = 0
for x in range(10): 
    for y in range(5):
        c += 1
print (c)

Answer

Output
50
Explanation

Outer loop executes 10 times. For each iteration of outer loop, inner loop executes 5 times. Thus, the statement c += 1 is executed 10 * 5 = 50 times. c is incremented by 1 in each execution so final value of c becomes 50.

Answer