$wpdb->flush(); breaks the loop
In the code you posted in your other question, your call to flush() is using the wrong variable: $wpdp->flush();. Since this is an undefined variable, it’s likely that you’re simply getting a PHP runtime error at this point, stopping page execution.