MCQ Single Best Answer Moderate

QWhat is the correct syntax for a while loop in Python?

ID: #23081 While Loop in Programming Language 85 views
Question Info
#23081Q ID
ModerateDifficulty
While Loop in Programming LanguageTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A while i < 10:
  • B while (i < 10);
  • C while (i < 10)
  • D while i < 10 {}
Correct Answer: Option A

Explanation

In Python, the correct syntax for a while loop includes the keyword while followed by a condition and a colon (:). The loop's body is indented and will keep executing as long as the condition is true. Option B represents incorrect syntax due to the semicolon, which is not required in Python. Option C is incorrect because it lacks the colon, and Option D is incorrect because it uses curly braces, which are not used for loops in Python. The while loop in Python is widely used for running a block of code as long as a given condition remains true, making it useful for repeating tasks without knowing in advance how many iterations are needed.

No Previous Next Question

Share This Question

Challenge a friend or share with your study group.