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:
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:
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.