Imagine a for loop iterated 20 times and an array containing only 5 elements. How we can ensure that all elements will be printed inside the loop exactly 4 times ? Take a look on following sample:
public class RangeTip {
@Test
public void test() {
int i = 0;
String[] words = {"A", "B", "C", "D", "E"};
for (; i < 20; i++) {
System.out.println(i+") "+words[i%words.length]);
}
}
}