Java Process Control

Source: Internet
Author: User
Tags case statement

Process Control

4.1 Looping Structure
4.1.1 Classification
(i) while loop
While Loop statement is also called conditional judgment statement, it loops in a condition that controls whether the statement continues to execute repeatedly. The syntax format is as follows:
while (conditional expression) {
Execute statement
}
when the return value of the conditional expression is true, the statement in "{}" is executed, and when the statement in "{}" is executed, the return value of the conditional expression is re-judged until the returned result is false, exiting the loop.
(b) Do: While Loop
do: While loop statements are similar to while statements, the difference between them is that the while loop statement first determines whether the condition is set up and then executes the loop body, and do. The While Loop statement executes a loop first, then determines whether the condition is true, that is, do. The program segment in the while loop statement brace is executed at least once. Syntax:
do{
Executes the statement
}
while (conditional expression); the
(three) for Loop
For Loop statement is one of the most useful looping statements in Java programming. A For loop can be used to repeatedly execute a statement until a condition is satisfied. Syntax:
for (expression 1; expression 2; expression 3)
{
statement sequence
}
Expression 1: Initialize the expression, which is responsible for initializing the variable.
Expression 2: A looping statement expression with a Boolean expression that specifies a loop condition.
  Expression 3: The post-loop action expression, which is responsible for trimming the variable and changing the loop condition.
(four) Jump statement
(1) The break statement
Break statement is used to terminate the following case statement, which is used to force exit loops, that is, to ignore any loop conditions and other statements in the loop body. The
(2) Continue statement
Continue statement can only be applied to for, while, do: The while Loop statement, which allows the program to jump directly to the following other statements, into the next loop.
(3) Comparison of break statements and continue statements
   1. Use cases
   break can be used in switch structures and looping structures
    Continue can only be used in looping structures
   2.
   break statement terminates a loop, and the program jumps to the next statement outside the loop block.

Continue jump out of this cycle and into the next cycle

4.2 Branch Structure
1. If statement, which is used to tell the program to execute a program in the case of a condition, but to execute another statement in another case. The IF condition statement can be divided into simple if conditional statements, if....else statements, and If...else if multi-branch statements.
[1] Simple if condition statement
if (Boolean expression) {
Statement sequence
}
Boolean expression: The necessary parameter, which indicates that it finally returns a Boolean value that can be a simple Boolean variable or constant, or an expression that uses a relationship or Boolean operator.
Statement sequence: Optional parameter. Can be one or more statements that execute when the value of an expression is true.
[2]if...else Statement
The If...else statement is the most commonly used form of a conditional statement, and it handles the choice of a condition, usually by doing some sort of processing if a certain condition is met, or another processing.
if (expression) {
Several statements
}else{
Several statements
}
The value of the expression within () after the if must be of type Boolean. If the value of the expression is true, the compound statement immediately following the statement is executed, and if the value of the expression is false, the compound statement after else is executed.
[3]if...else If statement
The If...else if multi-branch statement is used to handle the case of an event. It usually behaves as if some sort of condition is met, otherwise the other processing is performed if another is satisfied.
if (conditional expression) {
Statement sequence One
}else if (conditional expression 2) {
Statement sequence Two
}
... else if (conditional expression N) {
Statement sequence N
}
Conditional expression: The last return-worthy type must be a Boolean type
Statement sequence: Can be one or more statements, when the value of expression 1 is true, the statement sequence 1 is executed, when the value of the conditional expression 2 is true, the statement sequence 2 is executed, and so on.
2.switch statements
The value of an expression in a switch statement must be an integer or a character type, and the constant 1-n must be integer or character. The switch statement evaluates the expression first, and if the value of the expression is the same as the value of the variable following a case, then several statements after the instance statement are executed until a break statement is encountered. There is no break statement in the case statement, and several statements in the following case continue to be executed until a break statement is encountered. If it does not exist, and the value of the expression in the switch statement is not the same as the constant value of any case, switch does not do any processing.
Grammar:
Switch (expression) {
Case Constant Value 1:
Statement Block 1;
Break
...
Case constant Value N:
statement block N;
Break
}

Java Process Control

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.