JAVA looping structure-for, while and Do...while

Source: Internet
Author: User

The sequential structure of a program statement can only be executed once. If you want the same operation to execute multiple times, you need to use the loop structure.

There are three main loop structures in Java:

    • While loop
    • Do...while Cycle
    • for Loop

An enhanced for loop that is primarily used in arrays is introduced in Java5.

The break keyword

Break is used primarily in loop statements or switch statements to jump out of the entire block of statements.

Break jumps out of the innermost loop, and continues execution of the statement below the loop.

Continue keywords

The Continue is suitable for any loop control structure. The function is to let the program jump immediately to the next iteration of the loop.

In the For loop, the continue statement causes the program to jump immediately to the UPDATE statement.

In the while or Do...while loop, the program immediately jumps to the judgment statement of the Boolean expression.

JAVA looping structure-for, while and Do...while

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.