Bird
0
0

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

easy📝 Syntax Q12 of 15
PHP - Loops
Which of the following is the correct syntax to start a for loop in PHP?
Afor ($i = 0; $i < 5; $i++) {
Bfor i = 0 to 5 {
Cloop ($i = 0; $i < 5; $i++) {
Dforeach ($i = 0; $i < 5; $i++) {
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct PHP for loop syntax

    PHP uses for ($i = 0; $i < 5; $i++) { to start a for loop.
  2. Step 2: Check other options for syntax errors

    Options B, C, and D use incorrect keywords or formats not valid in PHP.
  3. Final Answer:

    for ($i = 0; $i < 5; $i++) { -> Option A
  4. Quick Check:

    PHP for loop syntax = A [OK]
Quick Trick: PHP for loops use semicolons and parentheses [OK]
Common Mistakes:
  • Using 'loop' instead of 'for'
  • Missing semicolons in for loop
  • Using 'foreach' incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes