Completed
Loop Control + Nesting
Questions From This Challenge
Q1mcq1 mark
What is the output of the following code (values printed, in order)?
for i in range(1, 10):
if i == 5:
break
print(i)
1,2,3,4 ✓
1,2,3,4,5
1,2,3
1,2,3,4,5,6,7,8,9
Q2mcq1 mark
What is the output of the following code (values printed, in order)?
for i in range(1, 6):
if i == 3:
continue
print(i)
1,2,4,5 ✓
1,2,3,4,5
1,2,4
1,2,3,5
Q3mcq1 mark
What is the output of the following code?
count = 0
for i in range(1, 4):
for j in range(1, 3):
count += 1
print(count)
6 ✓
3
2
9
Q4mcq1 mark
In a nested loop, when a break statement executes inside the inner loop, what happens?
Only the inner loop terminates; the outer loop continues to its next iteration ✓
Both the inner and outer loops terminate immediately
The outer loop terminates but the inner loop restarts
break has no effect inside a nested loop
Q5mcq1 mark
What is the output of the following code?
total = 0
for i in range(1, 4):
for j in range(1, 4):
if j <= i:
continue
total += 1
print(total)
3 ✓
6
9
4
Q6output1 mark
What is the output?
i = 1
while i <= 10:
if i == 6:
break
print(i)
i += 1
Correct output:
1
2
3
4
5Q7output1 mark
What is the output?
i = 0
while i < 10:
i += 1
if i % 2 == 0:
continue
print(i)
Correct output:
1
3
5
7
9Q8output1 mark
What is the output?
for i in range(1, 3):
for j in range(1, 3):
print(i * j)
Correct output:
1
2
2
4Q9output1 mark
What is the output?
for i in range(1, 4):
for j in range(1, 4):
if j == 2:
break
print(i, j)
Correct output:
1 1
2 1
3 1Q10output1 mark
What is the output?
for i in range(1, 4):
for j in range(1, 4):
if i == j:
continue
print(i, j)
Correct output:
1 2
1 3
2 1
2 3
3 1
3 2Q11output1 mark
What is the output?
count = 0
while True:
count += 1
if count == 4:
break
print(count)
Correct output:
4Q12output1 mark
What is the output?
i = 1
total = 0
while i <= 3:
for j in range(1, 4):
if j == 3:
continue
total += j
i += 1
print(total)
Correct output:
9Q13output1 mark
What is the output?
result = 0
for i in range(1, 4):
for j in range(1, 5):
if j == i:
break
result += 1
print(result)
Correct output:
3Q14output1 mark
What is the output?
n = 0
total = 0
while n < 20:
n += 1
if n % 5 == 0:
continue
if n > 12:
break
total += n
print(total)
Correct output:
63Q15output1 mark
What is the output?
total = 0
for i in range(1, 5):
if i == 3:
continue
for j in range(1, 4):
if j == 2:
break
total += (i * j)
print(total)
Correct output:
7