Java-preliminary Understanding-Chapter III-Circular structure

Source: Internet
Author: User

I. Overview

The representative statement of the cyclic structure is three, While,do while,for.

Recall the previous structure of the knowledge points explained, the structure is divided into such several, sequential structure, judging structure, selection structure, cycle structure. Where the judging structure is an if statement, there are three types of formats. The selection structure is a switch statement.

The three statements of the looping structure have a fixed format like the IF statement, the switch statement, which was previously learned.

Two. While statement

The structure of the while loop statement is as follows:

while (conditional expression)


Execute the statement;


Parse the while statement, as in the previous If,switch statement, there will be some data in front of these statements to determine the data. When the program

When you see the while keyword, it means that you may want to loop, as for the loop or not, depending on the final result of the conditional expression, (the conditional expression, regardless of how long it is written or how short it is, whether it's ture or false, without the Boolean type of data is wrong). When it is determined to be true, then the execution statement is executed, and the execution statement is called the loop body. When the loop body execution is finished, then the conditional expression is judged, and if it is, then it executes until the condition is not met and exits the while statement.

While statements and if format 1 have similarities, first structurally, only the keyword is different, and then there is a difference is that one execution once on the exit, one to execute multiple times.

While statements have two elements, one is a loop condition, the other is the number of loops, while the while is controlled by two points. The number of cycles is in fact subject to conditions, once the condition is not satisfied will exit.

There is also a point of note, as shown below, when added after a while (conditional expression), where the loop body is missing from the while statement, and the subsequent statements are no longer executed. This and if statement does not pass, if is directly past, supposedly, switch should also passed, experiment, switch directly error. If the past can be passed (format 1), it should be related to the ability to omit {}. It is the equivalent of omitting {}, and there is no execution statement.

Three. Do While statement

The Do and statements are structured as follows:



Execute the statement;


while (conditional expression);

The Do-while statement is characterized by the fact that the loop executes at least once, regardless of whether the loop condition is satisfied.

The difference between do and while is that the order is different, so what is the purpose of defining both?

Java-preliminary Understanding-Chapter III-Circular structure

Related Article

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: 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.