What are common pitfalls to avoid when learning PHP, particularly with regards to loops like do, while, and for?

One common pitfall when learning PHP loops like do, while, and for is forgetting to properly initialize loop variables or increment/decrement them within the loop. This can result in infinite loops or incorrect loop behavior. To avoid this, always make sure to initialize loop variables before the loop starts and update them correctly within the loop.

// Incorrect loop without proper initialization
$counter = 0;
do {
    echo $counter;
} while ($counter < 10);

// Corrected loop with proper initialization and increment
$counter = 0;
do {
    echo $counter;
    $counter++;
} while ($counter < 10);