Java Control process

Source: Internet
Author: User

Branch control

If/else statements

Dual Branch:

if (Boolean expression) {//Expression is true execution Statement 1}else{//Expression is false then execute statement 2}

Multi-branch:

if (Boolean expression 1) {//Expression 1 is true the statement executed by 1}else if (Boolean expression 2) {//Expression 2 is true for statement 2} ... else{//all expressions above are false to execute statement 3}

Switch statement

Multi-Branch

The switch (expression) {//Expression matches the following constant expression, and the corresponding statement is executed in case constant expression 1: statement 1 case constant Expression 2: statement 2 ... case constant expression N: statement n default: statement n+1}

Loop control

While

while (Boolean expression) {//Expression is true to execute loop body//loop body}

Do While

do{///loop body//execute the contents of the loop body first, then execute the boolean expression//execute the Loop body again, judge the Boolean expressions, and true to continue Otherwise exit the Loop}while (boolean expression);

For

for (expression 1; expression 2; expression 3) {//Expression 1 is: The initial state of the loop such as int i = 0; Expression 2 is: Determines the number of cycles such as the length of the array or the size of the collection//Expression 3 is: Change the initial state such as i++; I loop accumulate//loop body}

Combine your own past experience with a small tip using branching and looping:

The simple requirement description is the entity class Person class, the field Name,age,address, the collection List<list<string>>, and the collection content in the collection is the property value of the person class, such as the inner layer list< String> the first set of Contents Tom, New York, now needs to load the inner list<string> into the person object, and the whole set becomes the list<person>

The

Outer list is represented by a list, and the inner layer is represented by LISTN,

    List<Person> persons = new ArrayList<Person> ();   //Final Result set           for  (int i = 0;  i < list.size; i++)  {      list1 =  List.get (i);        person = new person ();        for (int j = 0; j < listn.size; j++) {                   switch (j)         case 1: person.setname (List1.get (j));         case 2: person.setage (List1.get (j));         case 3: person.setaddress (List1.get (j));         persons.add (person);//Load the object into the set       }          } 


This article is from the "Qinguan" blog, make sure to keep this source http://11083953.blog.51cto.com/11073953/1732442

Java Control process

Related Article

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.