`forEach` instead of `while` would eliminate the need for `i`