Write the program, use the continue statement to implement the Loop body filter, filter the "Eagle" string, and do the appropriate processing, but discard all the code after the continue statement. Where encounters the eagle string for specific processing, and then skips general processing with the continue statement.
Copy Code code as follows:
public class Continue {
public static void Main (string[] args) {
string[] array = new string[] {"Egret", "Red-crowned Crane", "Oriole", "Parrot", "Crow", "Magpie",
"Eagle", "cuckoo", "Eagle", "Gray-Grain Bird", "Eagle", "Lark"};
SYSTEM.OUT.PRINTLN ("There are many birds in my garden, but recently a few eagles, please help me take them away.") ");
int eaglecount = 0;
for (String String:array) {//foreach traversal array
if (String.Equals ("Eagle")) {//If you encounter an eagle
System.out.println ("Found an eagle, has caught the cage.") ");
eaglecount++;
continue;//Interrupt Loop
}
System.out.println ("Search for birds, found:" + string);/otherwise output array element
}
System.out.println ("Caught" altogether: "+ Eaglecount +" only eagle. ");
}
}
The effect is as shown in the figure: