Java Basics (4)

Source: Internet
Author: User

First, commissioning

Step 1: Set a breakpoint (you cannot set a breakpoint in an empty space)

Step 2: Start debugging

Step 3: Debug the Code (F6 single-step skip)

Notebook Fn+f6 (F5)

Step 4: End Debugging

Mastering the benefits of debugging?

1. Clearly see the order in which the code executes

2. Quickly navigate to where the exception code appears and help modify or improve the code

Second, while loop

1, the advantages of the cycle?

Reduce duplication of code writing

The program will be more concise

2. Grammar

while (expression) {//1, the expression is a "loop condition", the result must be            code in Boolean type//2, {}, "loop operation (body)"            //3, "Iteration part" change loop condition, end loop        }

3, Characteristics: First judge, then execute

4. While loop has 2 common ways

Mode 1:

While (1, loop condition determines whether strings are equal) {

2, loop operation//3, receive the string in the keyboard again, change the loop condition, to end the loop

}

Mode 2:

While (1, the loop condition int variable is compared with the relational operator) {

2. Cyclic operation

3, iteration part, int variable + + or--, to change the loop condition, end the loop operation

}

Third,Do....while cycle

1, applicable occasions: first cycle 1 times, according to the conditions of judgment, recycling

2. Grammar

do{

  2. Circulating body (cyclic operation)

3, change the circulation condition}while (condition); 1. Cyclic conditions

Iv. use cases for the For loop

While loop--first judge, then loop

While (1, conditional expression ) {

//2 , cyclic operation

//3 , changing the loop condition expression

}

do...while--first cycle, then judge

do{

//2 , cyclic operation

//3 , changing the loop condition expression

}while (1. Conditional Expressions );

The above 2 cycles, generally used in the case of uncertain cycle times

Number of known cycles, preferred for loop

V. Syntax for a FOR loop

For (1. Initial Part  ; 2. condition judgment ; 3. Iteration Section ) {

4. cyclic operation

}

Vi. execution order of the For loop

Section 1 Secondary Cycle

Perform the initial part first ( only when the 1 loop is executed )

And then the condition is judged.

If the condition is met, the loop operation is performed

If the condition is not met, the loop ends

Section 2~n sub-cycle-condition Satisfaction

After the 1th time the loop operation is completed

Perform the Iteration section first

And then the condition is judged.

If the condition is met, the loop operation is performed

If the condition is not met, the loop ends

Seven, 2 keywords

Break " General and if conditional statements are used together "

To end a switch statement in a switch statement

To end or terminate a loop in a loop structure

Continue

In the loop, end the loop and go to the next loop.

Java Basics (4)

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.