Home > Back-end >  The Java process control statements
The Java process control statements

Time:02-19

One, the if... The else statement

if... The else statement can be viewed as there are four kinds of forms:

If statement




if... The else statement




if... Else if... The else statement




Nested if... The else statement



Second, a switch statement

The switch case statement has the following rules:

1, variable type can be in the switch statement: byte, short, int or char, enum, starting from Java SE 7, the switch support String String type, at the same time case labels must be String constants or literal,

2, the switch statement can have multiple case statement, behind each case with a value, and to compare the colon,

3, a case statement of values in the data type must be the same as the variable data types, and the only constants or literal constants,

4, when the value of a variable with a case statement values are equal, then the case statement statement after the start, until the break statement appeared to jump out of the switch statement,

5, when break statement is encountered, the switch statement is terminated, the program to jump to the back of the switch statement statement execution, case statement don't need to include the break statement, if there is no break statement, the program will continue to carry out a case statement, until the break statement,

6, the switch statement can contain a default branch, the branch is generally a switch statement last branch (can be in any location, but generally in the final), the value of the default in no case statement execution and variable values are equal, the default points don't need a break statement,

Format:



Three, loop statement

1, the for loop

Format:


2, while loop

While is the most basic loop, its structure is:

Format:


3, the do... The while loop

The do... The while loop and the while loop, the difference is that the do... The while loop is executed at least once,

Format:



4, Java enhanced for loop

Java 5 introduces a is mainly used for an array of enhanced for loop, but need to note that Java enhanced for loop values only. No assignment

Format:


5, break, continue to return
Break: the end of the cycle
The continue: end of the cycle, into the next cycle
Return: end of a method, the method of over, end of cycle nature was
Note: in a while and do... While using the continue to pay attention to the position update statement,
  • Related