Goto labeled statement in Java example

Goto in for cycle Java example source code.
MainClass.java

public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = {"nothing", "Hello", "people"
				, "bye-bye", "hello", "world!", "end" };
 
	    OuterLoop: for (int i = 0;i<6; i++) {
	        for (int j = 0; j < arrayOfString.length; j++) {
	        	if (arrayOfString[j].equals("world!")) {
	            continue OuterLoop; // as goto from Csharp, or C/C++
	          }
	          System.out.println(arrayOfString[j]);
	          System.out.println(i);
	          if (i == 1) {
	        	  System.out.println("break");
 
	        	  break OuterLoop;
	          }
	        }
	      }
 
	}
}
/*
nothing
0
Hello
0
people
0
bye-bye
0
hello
0
nothing
1
break
*/
This entry was posted in Android Examples Code and tagged , , , , . Bookmark the permalink.


Comments are closed.



12,681 views