I know this code is copied, but `breakable` and `break` are kind of weird to use and expensive. It would be better to just add a flag for shouldStop and do `while (i < k && !shouldStop)`.