The first small experience of the three major cycles----Java

Source: Internet
Author: User

The three major cycles of Java include while 、、、 does while 、、、 for

(1) Grammatical differences:

While loop

while (loop condition) {

Cyclic operation (body)

}

Do and loop

bo=

Cyclic operation (body)

}while (cyclic conditions);

For loop

for (initialize; loop condition; iteration) {

Cyclic operation (body)

}

(2) Order of execution:

While loop: first judgment after execution

Do and loop: Judge after first execution

For loop: first judgment after execution

(3) Applicable situation:

When the number of cycles is determined, the for loop is usually used;

When the number of cycles is uncertain, the while loop or do While loop is usually selected;

Note: 1, the code indentation, to have a level, to do a good programmer;

2, the circulation can be normal exit, to avoid the death cycle;

3, the loop variable can have multiple

4, no matter which cycle, there are essential 4 parts: The initial part, the cycle condition, the loop body, the iteration part.

The first small experience of the three major cycles----Java

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.