QuestionQ247

VerifiedControl Flow – Conditional Blocks and Loops

What occurs when the user executes the following code?

Question Image

Explanation

The loop increments speed by 2 on every pass and only reaches the print statement when the if-condition speed > 10 is false, which holds for the increments producing 2, 4, 6, 8, and 10 — five passes in total. Once speed becomes 12 and continues to climb to 30, the condition is true on every remaining pass, so continue skips the print statement for the rest of the loop, and no further asterisks are added before the loop terminates. The net visible output is therefore five asterisks printed side by side on the same line.

Community Discussion

No comments yet. Be the first to start the discussion!