Can this `while` loop be turned into a simple expression?