Q:

If exit array, enter from the other side

How can I do this for example if I have 1, 2, 3, 4, 5, 6, 7 array and I am in 4th position (number 5) and if you have to move it to the right 4 positions you should be in position 1 (number 2). The same goes with negative numbers but you move to left. I guess there is a need of while(true) loop?

A:

Lets assume i is the index and n is the size of the array. 
For positive i the needed index = i%n
For negative i i%n returns negative residue, so the needed index is n+i%n
You can use  
int index(int i, int n) {
   return i%n < 0 ? n + (i%n) : i%n;
}

