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