Are there any potential issues with using flush() within a while loop compared to a for loop in PHP?

Using flush() within a while loop can potentially cause performance issues as it continuously sends output to the browser, which can slow down the script execution. It is more efficient to use a for loop with a buffer to accumulate the output and then send it all at once after the loop has completed.

ob_start();

for ($i = 0; $i < 10; $i++) {
    echo "Output line $i\n";
}

ob_end_flush();