It's because you have set $flag to '0', which is an uninterpolated string containing the character '0', a true value.
Instead, you should set $flag to zero, (0), without the single quotes. This will evaluate to false and make your logic all happy.
In reply to Re: getting a while loop to terminate
by thezip
in thread getting a while loop to terminate
by Aldebaran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |