You're making it seem like the behaviour is random-- it is not.

The parser will consistently parse the while one time and then fail, which is what Horstl's simplified example shows.

There's a simple explanation for why it does it once, and there's an equally simple explanation for why it would fail the second time:

The first time around is parsed normally as if reading normally through a page in a book. Once the end of the while loop is found, the parser has to jump back, but in this case, when there is an ambiguity of where to jump, the parser cannot "find" the beginning of the loop and fails.

Why mIRC is not able to jump back even though it found the while loop the first time may have to do with the implementation details of how the parser keeps state during execution. The results, however, are not random.