Question: Working in Java, I'm looking at a way to loop over a range of indices, based on a set number of entries that are needed per page. The use for this is to return specific elements that are on a specific page.

For instance, there are five elements per page, and I want all of the elements on page 5. If the starting index is 1 (not zero) then that means this method should iterate over indices 21-25. 

How would i go about doing this?

(sorry for the lack of tags, i'm not sure what else this should be tagged with..)

Answer: 
Just do a little math in your code. The product of the elements per page and the page number is the last index you want. Then the start index is one past the ending index of the page before it.

```
int start = (page - 1) * (elementsPerPage) + 1;
int end = page * elementsPerPage;
for (int i = start; i <= end; i++)
{
    // Your logic here
}

```

This was edited to show the calculations separately.
Do you mean something like: 

```
for(int i = pageNumber*5-4; i <= pageNumber*5; i++)
{
  //access indices with i here
}

```