State True or False

“In a Python program, if a nested loop is given with a continue statement in the inner loop, it skips the current iteration of the inner loop and resumes the next iteration of the outer loop.”

Answer:

Answer by student

False

Detailed answer by teachoo

The statement is false because the continue statement in the inner loop only skips the current iteration of the inner loop and resumes the next iteration of the inner loop , not the outer loop.

To understand this, let’s look at an example of a nested loop with a continue statement in Python:

[True or False] “In a Python program, if a nested loop is given with - Teachoo Sample Paper - Computer Science Class 12

As you can see, the continue statement only skips the inner loop when j == 2 , but it does not affect the outer loop. The outer loop still iterates from 1 to 3, and the inner loop still iterates from 1 to 4 for each value of i .

If we want to skip the current iteration of the outer loop and resume the next iteration of the outer loop, we need to use the break statement instead of the continue statement . The break statement exits the inner loop completely and moves on to the next iteration of the outer loop.

For example:

part 2 - Question 1 [True or False] - Teachoo Sample Paper - Computer Science Class 12 - Solutions to CBSE Sample Paper - Computer Science Class 12 - Computer Science - Class 12

Here, the break statement terminates the inner loop when j == 2 , and resumes the next iteration of the outer loop.

So, the correct answer is False.

Remove Ads
Teachoo · Class 12 Explore Class 12
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh is an IIT Kanpur graduate and has been teaching for 16+ years. At Teachoo, he breaks down Maths, Science and Computer Science into simple steps so students understand concepts deeply and score with confidence.

Many students prefer Teachoo Black for a smooth, ad-free learning experience.