Bird
0
0

Which of the following is the correct syntax for a while loop in PHP?

easy📝 Syntax Q3 of 15
PHP - Loops

Which of the following is the correct syntax for a while loop in PHP?

Awhile { condition } // code
Bwhile (condition) { // code }
Cwhile condition: // code endwhile;
Dwhile (condition); { // code }
Step-by-Step Solution
Solution:
  1. Step 1: Recall PHP while loop syntax

    The correct syntax uses parentheses around the condition and curly braces for the code block.
  2. Step 2: Check each option

    while (condition) { // code } matches the correct syntax. while { condition } // code has wrong braces, C uses alternative syntax but is incomplete, D has a semicolon breaking the loop.
  3. Final Answer:

    while (condition) { // code } -> Option B
  4. Quick Check:

    Correct syntax uses parentheses and braces [OK]
Quick Trick: Use parentheses for condition and braces for code [OK]
Common Mistakes:
  • Missing parentheses
  • Using semicolon after while condition
  • Confusing alternative syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes