Java Basics (4) Looping statements

Source: Internet
Author: User

1.while Loop statement

Grammar

while (loop condition) {

Statement of the loop operation

}

Points:

Judge and execute first.

Variable cycle times

Avoid dead loops

2.do-while Loop Statements

Grammar

The while loop is also called the type loop

Do-while cycle, also known as the cycle

do{

Looping operation statements

}while (cyclic conditions);

Execute once to meet the loop condition continue execution

Points:

Perform the re-judgment first.

Execute at least once

Do not miss the last semicolon

3.for Loop statement

Grammar

for (expression 1; expression 2; expression 3) {

Condition satisfies execution

}

Expression 1: Parameter initialization

Expression 2: Conditional judgment

Expression 3: Updating the loop variable

Points:

Number of cycles determined

Comparison of While loops and for loops

Loop type

The while loop is an indeterminate type of loop

The For loop is a deterministic loop

Convert each other

While loops and for loops can be converted to each other

Use occasions

When the number of loops determines the thing, use the For loop

When the number of cycles is indeterminate, use the while loop

4. Double for Loop

Grammar

for (expression 1; expression 2; expression 3) {Outer loop

for (expression 1; expression 2; expression 3) {Inner loop

}

}

Parsing: A loop containing a circular statement in a loop is called a double loop,

When the outer loop once, the inner loop to loop, and then back to the outer loop into the next cycle, until the outer loop is finished.

5.break syntax and usage

Grammar

Break: Change the program flow, in the loop statement, to jump out of the loop and execute the following statement

Points:

End of Loop

Change the number of loop executions

Just jump out of this loop

6.continue syntax and usage

Grammar

Continue effect: Skips the cyclic weight remaining statement and executes the next loop

Points:

No end loop

No change in loop execution times

Works only in the loop of this layer

Java Basics (4) Looping 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.