Question Detail

COS 102 6 lecture note; fundamentals of programming Objective Question

Question

Which of the following correctly represents the basic syntax for a `while` loop in Python?
Options
A <code>while (condition) { body }</code>
B <code>while condition:</code><br><code> body</code>
Correct Answer
C <code>loop condition:</code><br><code> body</code>
D <code>while condition;</code><br><code> body</code>
Correct Answer

Option B is the correct answer.

Detailed Explanation

Page 61 of the document explicitly shows the syntax: while condition: body, emphasizing the colon and indentation for the loop body.

Hint

Remember Python's reliance on colons and indentation for defining code blocks, similar to `if` statements and function definitions.

Question Info