A while back I had the same problem (paginating through an API) and I ended up applying a repeat( // break()) style loop.
The reason was that it was impossible to know in advance the number of pages with meaningful result, so a for() loop was not feasible and I had to keep iterating until finding an empty page.
This was the (simplified) construction:
i <- 1
result <- data.frame()
repeat({
data <- scrape_the_api(page = i)
if(nrow(data)==0) break() # the end was reached...
result <- rbind(result, data)
i <- i +1
})
some_fancy_processing(result)
This construction makes sure the API is called at least once, and breaks once an empty result is returned.