Writing a program is to create an array of strings that, when traversed using a foreach statement, immediately interrupts the loop if it finds that the array contains the string "Eagle". Then you create a two-dimensional array of integer types, loop through the two-layer foreach statement, and when you find the first array element less than 60, you immediately interrupt the entire two-tier loop, rather than the inner loop.
Copy Code code as follows:
public class Foreach {
public static void Main (string[] args) {
System.out.println ("\ n-------------example of interrupting a single layer of loops-------------");
Create an array
string[] array = new string[] {"Egret", "Red-crowned Crane", "Oriole", "Parrot", "Crow", "Magpie",
"Eagle", "cuckoo", "Eagle", "Gray-Grain Bird", "Eagle", "Lark"};
System.out.println ("Before you find the first eagle, tell me what the birds are.") ");
for (String String:array) {//foreach traversal array
if (String.Equals ("Eagle"))//If you encounter an eagle
break;//Interrupt Loop
System.out.print ("have:" + string+ ""); Otherwise output array elements
}
System.out.println ("\ n-------------example of interrupting a double loop-------------");
Create an array of scores
int[][] Myscores = new int[][] {{67, 78, 63, 22, 66}, {55, 68, 78, 95, 44}, {95, 97, 92, 93, 81}};
System.out.println ("Baby this test score: \ n math \ t Chinese T-English T-art T-history");
No1:for (int[] is:myscores) {//Traverse score Table
for (int i:is) {
System.out.print (i + "t"); Output results
if (I < 60) {//If there is a failure in the middle, immediately interrupt all output
System.out.println ("\ n et cetera," + i +) What are the points? Why didn't you pass the exam? ");
Break No1;
}
}
System.out.println ();
}
}
}
The effect is as shown in the figure: