How can the while(): endwhile; syntax in PHP be utilized to enhance the structure of code generating HTML output?

The while(): endwhile; syntax in PHP can be utilized to create a loop that generates HTML output dynamically based on certain conditions. This can help improve the structure of code by reducing redundancy and making it easier to manage and maintain.

<?php
// Example code snippet utilizing while(): endwhile; syntax to generate HTML output
$data = [1, 2, 3, 4, 5];

echo '<ul>';
while($item = array_shift($data)):
    echo '<li>' . $item . '</li>';
endwhile;
echo '</ul>';
?>