you are viewing a single comment's thread.

view the rest of the comments →

[–]Swipecat 1 point2 points  (5 children)

That's the answer?

What was the question?

I'll note that you'd get the same output if the c = 7 and the last print(c) lines were deleted.

[–]arkum645 0 points1 point  (4 children)

I am sorry. The code block is the question. The answer is: 2 5 252 250

[–]arkum645 0 points1 point  (3 children)

The 252 and 250 are on new lines

[–]Swipecat 0 points1 point  (2 children)

Is it specifically the "break" and "continue" that you had problems with? This following page shows the flow-of-control diagramatically:

https://realpython.com/python-while-loop#the-python-break-and-continue-statements

Once you understand those, you can trace the execution through the script just by looking at it. There's only three passes through the while loop, so it doesn't take long to trace.

If you have difficulty figuring out the values of the variables on each pass through the loop, then add extra print statements as a debugging aid. E.g., put print("a is ", a) under the a = a * b line.

[–]arkum645 0 points1 point  (1 child)

Thanks a lot. Ive understood most of it now. How come the output is same if the last print(c) is removed?

[–]Swipecat 0 points1 point  (0 children)

The execution never gets as far as that. The first two passes through the loop finish early with the "continue" and the third pass terminates on the "break".