Consider having nextRow() return an Option so that you can detect when there are no more rows left without using an infinite loop.