Question related to 'Interruption of Loop iteration : Continue'

My Question is: If the loop statement terminates immediately why is the print(counter) statement being executed?

Context/Reference:
In the course section for Continue: Loop iteration the following program was given:

counter = 0

while counter < 10:
counter += 1
if counter == 3:
continue
print (counter)

print (“Outside the loop!”)

And the expected output was given as
1
2
3
4
5
6
7
8
9
10
Outside the loop!

The definition/explanation for a ‘continue’ statement was
" continue : It immediately terminates the current loop iteration. Execution jumps to the top of the loop, and the condition is re-evaluated to determine whether the loop will execute again or terminate."

HI @sanjayatj

The output should be:

1
2
4
5
6
7
8
9
10
Outside the loop!

you can run the code yourself to check!

Hi @simon.steinmann91

Thank you for your reply.

My question however, was why is the output that way when the print statement comes after the continue. What I understood from the theory is that when the continue statement is read the code immediately reverts back to the point where the condition is being checked. So if the print is after the continue why is it being executed 10 times.
Kindly let me know if my understanding is wrong.

Oh! Sorry. My bad! I got it now :sweat_smile: . Only when it is 3 the continue statement will be executed! Sorry for any confusion i caused!

you understood correctly. Test the code yourself, and look closely at my posted result, the ‘3’ is missing

Thank you Simon. :slightly_smiling_face: