in reply to while loop question

Of all of the possible “solutions” posted here, only VinsWorldcom’s strategy would ever pass muster in my shop.   Why?   Because it works (of course), and because it is instantly and abundantly clear and easily maintainable.   Provided that it can be clearly shown that the final value of my $lastFlag (a sensibly-named variable) at the if-statement can only be determined by the outcome of the while loop that immediately precedes it (which loop cannot be bypassed), this manner of clear software prose makes no pretenses about how it works and leaves no question that it does.   Furthermore, the logic can easily be extended to allow for any sort of tests and any number of tests to be performed within the loop and used to exit from the same.

Some Monks further advocate the use of last label_name syntax, noting that, particularly in complex logic which might involve multiple nested structures, the contextual meaning of a last statement sans target-label could become broken by a subsequent change that wrapped the statement in another loop.   This is reasonable.