I’ve written the following which does what I want it to do, but I think there’s a faster way than doing a conditional statement in the for loop.
int i,j,k,l;
int[] X = new int[] {111,222,333,444};
int XL = X.length;
for (i=0, j=1; i<XL; j=(j<XL-1)?j+1:0, i++) {
println("i:" +i +" j:" + j);
}
// returns:
// i:0 j:1
// i:1 j:2
// i:2 j:3
// i:3 j:0
Kerrek SB’s comment is my preferred solution.
Here it is rewritten to a bit more generic:
will return: