Program flow control in Java

Source: Internet
Author: User


I. Boolean logic
1. Boolean operators:
① short-circuit and--&&; judge two expressions, if the first one is true, continue to judge the second expression, if the first is false, you do not need to judge the second one to become larger
② and--&; judge two expressions, and if the first one is true, then you need to judge the second expression.
③ short circuit or--| | Judging the first one is true, you don't have to judge the second one. If the first one is false, continue judging the second one. A true truth, two true or true.
④ or--| judge the first one to be true, and the second one will be judged true. A true truth, two true or true. Whether the first one is true or not, you need to judge the second one.
⑤ or--^;
⑥ Non---! The meaning of negation
2. Boolean type:
The Boolean has two values, one is true, and the other is false. The default value is False.

Two. SELECT statement
If statement:
①if () {
}
②if (Boolean expression) {
If the Boolean expression is true, the statement executed
}else{
Executes when the Boolean expression is False
}
③if () {
}else if () {
}else{
}
④if () {
if () {
}else{
}}else{
}
2.switch statement:
①switch (This can only be byte,short,int,char.) After jdk7.0, it can be a string. Can only be variables of these types) {
Case Value:
Statement
Break (if there is no break he will keep going, know to meet break, or end)
Case Value 2:
Statement 2
Break (if there is no break he will keep going, know to meet break, or end)
...
Default
Statement (the statement block above does not satisfy the execution)
}

Three. Cyclic structure
①while (Boolean expression) the {///Boolean expression is true to execute this statement, and execution continues to return to judge this expression, and always loop knowing that the condition is not met.
Statement
}
②do{//regardless of whether the condition satisfies the need to execute a loop, the execution is completed continue to return to judge this expression, always loop know that the condition is not satisfied.
Statement
}while (boolean expression);
③for (initialization; Boolean expression; cyclic variable update) {//initialization is performed only once, then the condition is determined, the execution statement is satisfied, the variable is updated, the execution is met, and then
The secondary variable is updated so that the loop is exited until the condition is not met.
Statement
}

Four. Jump statements
①break statements
Used to jump out of the loop structure
It is also used in switch.
②continue statements
Used to jump out of the current loop.

All symbols are in the form of English half-width.

Program flow control in Java

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.