Please merge the two loops into one and use either goto or break instead of this flag.