Since it doesn't make any difference whether you use do/while or just while with a `true` condition, I tend to prefer regular while stylistically - makes the fact this is an infinite loop + breaks more obvious.

Also that whole set of ifs below really should be one big if/else if block.

Otherwise looks good.