Which of the following for loops is equivalent to a while loop?

Understand the Problem

The question lists several for loop structures and asks which one can be replaced by an equivalent while loop, implying that it is assessing knowledge of control flow in programming.

Answer

For loop: `for i in range(4, 12, 3): print(i, end=' ')`

A for loop such as for i in range(4, 12, 3): print(i, end=' ') is equivalent to the while loop i = 4; while i < 12: print(i, end=' '); i += 3.

Answer for screen readers

A for loop such as for i in range(4, 12, 3): print(i, end=' ') is equivalent to the while loop i = 4; while i < 12: print(i, end=' '); i += 3.

More Information

The for loop for i in range(4, 12, 3): sets i to 4, then increments i by 3 until i is no longer less than 12, making it functionally equivalent to the given while loop.

Tips

A common mistake is not matching the start, end, and step values between the for loop's range and the while loop's increment.

AI-generated content may contain errors. Please verify critical information

Thank you for voting!
Use Quizgecko on...
Browser
Browser