please write what is difference between these programs
In the first case, your do-loop terminates prematurely, and you have code following it that fixes it. In the second case, your do-loop terminates prematurely, and you don't have code following it that fixes it.
IMO, neither case is optimal. Maybe it would be better to fix the do-loop.
Henry