Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

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:

Continue Statement Example using a Python Program - Teachoo.png

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:

Break Statement Example using a Python Program - Teachoo.png

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.

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.