Work around rust#16151.

This replaces skip_while with a custom for loop. This can be reverted
when the Rust bug is fixed.