One, JAVA Process Control
Conditional Statement-if: Syntax format-if (single condition) as
Conditional Statement-if...else ... (Two choice one)
Conditional Statement-if...else If ... (multiple selection), can nest multiple else if
Conditional Statement-switch
Syntax Format-switch
switch (expression)
{
Case value 1: statement block 1
...
Case Value N: statement block n
Default: statement block n+1
}
Conditional Statement-switch (description)
The value of an expression can only accept int, Byte, char, short, enumeration, JDK1.6 string can also, do not accept other types of values, do not allow duplicate case value
When switch encounters the first case match, the program jumps to the tab location
Start the execution of all subsequent program code, regardless of whether the following case conditions match, until the break statement is encountered
Second, the circular statement
While:while (conditional expression)
{
EXECUTE statement block
}
Do...while:do
{
Executes the statement block;
} while (conditional expression);
For:for (initialization expression; cyclic conditional expression; post-loop action expression)
{
EXECUTE statement block
}
For example multiplication formulas:
private static void multiplication formula () {
for (int a=1;a<=9;a++) {
for (int b=1;b<=a;b++) {
System.out.print (A + "*" + B + "=" +a*b + "\ t");
}
System.out.println ();
}
}
Loop Interrupt Statement-break, continue
Interrupt statement
Labels can be used in multiple loops to specify the specific loop of interrupts
The break statement is used to terminate execution of a block of statements. Used in the Loop statement body, you can forcibly exit the loop.
"Break;" Statement: can appear in the while, Do...while, for, switch statement body.
Break Label statement: can appear in any body of the statement. The majority is still used in the loop.
The continue statement is used in the Loop statement body to terminate a looping process, skipping a loop that is not executed under the Continue statement in the loop body, and starting the next cycle.
"CONTINUE;" Statement: can only appear in the Loop statement while, Do...while, for
Java Looping statements