java - Want to exit from for loops -
i want exit 2 loops when count become 9. use break
can exit first loop. how can done?
arraylist<string> list = new arraylist<string>(); int count = 0; system.out.println("before entering loop"); for(int i=0;i<5;i++){ list.add("xyz"+i); for( int j=0;j<5;j++){ list.add("abc"+j); count++; if(count==9){ system.out.println("i want exit here."); break; } system.out.println("i="+i+"::j="+j); } system.out.println("------------"); } for(string str:list){ system.out.println(str); } }
you can use labels:
outer: (...) { // <-- ... (...) { if (...) break outer; // <-- } }
this covered in branching statements section of java tutorial , in jls §14.7.
Comments
Post a Comment