see the code:
public class Rainbow {
2. public static void main(
String[] args) {
3. int count = 0;
4. String[] colours = {"red", "orange", "yellow", "green",
5. "blue", "indigo", "violet"};
6. start: for (int i = 0; i < 5; i++) {
7. switch (i) {
8. case 0:
9. count--;
10. break;
11. case 3:
12. continue start;
13. case 4:
14. count--;
15. break start;
16. default:
17. count++;
18. break;
19. } // switch end
20. count++;
21. }
22. System.out.println(colours[count]);
23. }
24.}
1 Standard output will display 'red'.
2 Standard output will display 'green'.
3 Standard output will display 'indigo'.
4 Standard output will display 'violet'.
5 An ArrayIndexOutOfBoundsException will be thrown, halting the program
Answer is green(2)
-Lost somewhere in making out flow in continue statement.
Can someway explain the flow clearly with values in each iterations?
thanks,
rajiv