The concrete implementation _java of Java termination loop body

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.