The loop structure in Java

Source: Internet
Author: User

---restore content starts---

There are several looping structures in Java, which I summarize myself as: IF-ELSE selection structure, multiple if selection structure, nested if selection structure, switch selection structure, while loop, Do-while Loop, for loop and nested loop.

IF-ELSE Selection Structure: if (conditional expression) {statement block};else {statement block};

Multiple if selection structure: if (conditional expression) {statement block}; else if (conditional expression) {statement block}; else if (conditional expression) {statement block}; ........

Nested IF selection structure: In the while loop, the if selection structure is nested within the For loop.

Switch selection structure: switch (expression) {Case constant 1: statement; Break;case constant 2: statement; Break;........default: statement;} switch is mostly equivalent, because the case is followed by a constant.

While loop: while (loop condition) {looping operation}, while feature is: first judge the condition, the condition conforms to the loop operation, until the loop condition is not satisfied, is not in the execution loop!

Do-while loop: Do {cyclic operation}while (cyclic condition); it is characterized by: first do a cycle, in judging the cycle conditions, conditions, continue to execute the loop body, does not meet the conditions, exit cycle!

For loop: for (parameter initialization; loop condition; iteration) {Looping operation}

Nested loops: In the loop body, nested loops.

The For loop differs from the while loop in that the number of loops in the for loop is fixed, the for loop can be replaced with a while loop, and the while loop may not be replaced with a for loop.

In summary: The loop generally consists of four parts, which are cyclic variables, cyclic conditions, cyclic operations, loop iterations.

---restore content ends---

The loop structure in 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.