Java Basics---Do...while of Java loop Statements (23)

Source: Internet
Author: User

The do...while of the Java Loop statement

The Do...while loop is somewhat similar to the while loop syntax, but the execution process is quite different.

Syntax: 650) this.width=650; "src=" http://img.mukewang.com/536a018100011a0401720070.jpg "/>

Execution process:

<1>, perform the cycle operation first, and then determine if the loop condition is true

<2>, if the conditions are established, continue to implement < 1 >, < 2, until the cycle conditions are not established

Features: first execution, after judgment

Thus, the Do...while statement guarantees that the loop is executed at least once !

For example, still output 1000 times "I adore class net", using Do...while Implementation code: 650) this.width=650; "Src=" http://img.mukewang.com/ 536a01150001976604830150.jpg "/>

Code:

public class HelloWorld {
public static void Main (string[] args) {

int sum = 0; Save 1-50 even-numbered and

int num = 2; Represents an even number between 1-50

do {
Implementing Cumulative summation

Sum=sum+num;
num = num + 2; The value is added 2 for each execution once to determine the next cyclic condition

} while (NUM<=50); Repeat loop when value is met between 1-50

System.out.println (the sum of the even numbers within 50 is: "+ sums);
}
}


Operation Result:

The sum of the even numbers within 50 is: 650

This article is from "Ghost" blog, please make sure to keep this source http://caizi.blog.51cto.com/5234706/1547752

Java Basics---Do...while of Java loop Statements (23)

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