What potential pitfalls should be avoided when directly outputting HTML within a PHP while loop?

When directly outputting HTML within a PHP while loop, it is important to avoid mixing PHP and HTML code as it can lead to messy and hard-to-maintain code. Instead, it is recommended to separate the PHP logic from the HTML markup by using PHP opening and closing tags within the loop to echo out the desired HTML content.

<?php
// Sample PHP while loop with separate HTML output
$items = ['Apple', 'Banana', 'Orange'];

while ($item = current($items)) {
    echo '<li>' . $item . '</li>';
    next($items);
}
?>