Java Chapter Sixth

Source: Internet
Author: User

For loop

Grammar:

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

Loop body

}

The for Operation step is

1 "2" 4 "3" 1 ...

Expression 1: Assignment statement > Initial part of loop structure, assigning initial value to loop variable,

Expression 2: Conditional statement > Looping condition of loop structure,

An expression 3 assignment statement, usually using the + + or--operator > Iteration portion of the loop structure, typically used to modify the value of a loop variable,

Continue statement vs. break statement:

The break statement is used to terminate a loop, and the program jumps to the next statement outside the loop body.

The continue statement is used to jump out of this loop and into the next loop statement.

While Do-while for three statement operation order comparison

While loop structure: The condition is judged first, and the loop body is executed. If the condition is not true, exit the loop.

Do-while Loop structure: First executes the loop body, in the condition judgment, the loop body executes at least once.

For loop structure: The initialization part is executed first, then the condition is judged, then the loop body is executed, and finally the iterative part is calculated. If the condition is not true, jump out of the loop.

Java Chapter Sixth

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.