3. Process Control Statements

Source: Internet
Author: User

Pay attention to the point ~

1 Switch statements

Note that the value of the expression in the parentheses after the:1> switch must be an integer or character type

The value following the 2>case can be a constant value, such as 1, 2, or a constant expression, such as A + T, but cannot be a variable or an expression with a variable, such as a * 2

After the 3> case is matched, the program code in the matching block is executed, and if no break is encountered, the contents of the next instance block will continue to be executed until the break statement or switch statement block ends as

4> can merge case statements with the same functionality

5> the default block can appear anywhere, or you can omit the


2 for Loop statement

Some small details to keep in mind:

1. The three expressions in parentheses after the For keyword must be separated by ";", and three expressions can be omitted, but ";" cannot be omitted.

A. Omit "loop variable initialization", which can be initialized by an assignment statement before the for statement, such as:

B. Omitting "cyclic conditions" may cause the cycle to continue, which is what we often call a "dead loop" phenomenon, such as:

Avoid the appearance of a "dead loop" during programming so that the above code can use break in the loop body to force a bounce out of the loop

C. Omit "Cyclic variable change", you can change the loop variable in the loop body, such as:

2. For loop variable initialization and cyclic variable changes, you can use "," to initialize or change the values of multiple loop variables, as

3, the loop condition part can use the combination of logical operators expression, to express complex judgment conditions, but must pay attention to the priority of the operation, such as:


3 Break Exit Loop


4 Continue Skip Cycle

The function of continue is to skip the remaining statements in the loop body to perform the next loop.

3. Process Control Statements

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.