Java Basics---The while (22) of the Java Loop statement

Source: Internet
Author: User

The while of the Java Loop statement

In life, there are times when you need to repeat certain actions in order to accomplish a task. If you participate in a 10000-metre long distance running, you need to run 25 laps around the 400-metre track repeatedly. When implementing functionality in Java, it is often necessary to execute some code repeatedly, for example, in order to express "strong love", we want to output 1000 lines "I adore class net!" ”。 Obviously, at this time repeatedly knocked 1000 times output statement is not reliable drop!! So, there is a good way to solve the wood? There, looping statements !

3 types of loops commonly used in Java: While , Do...while, for

We're going to talk about while in this section.

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

Execution process:

< 1 >, determine if the condition behind the while is established (True/false)

< 2 >, when the condition is established, execute the operation code within the loop, then repeat < 1 >, < 2, until the loop condition is not established

Features: first judgment, after execution

Such as:

650) this.width=650; "src=" http://img.mukewang.com/5369a5910001ccb503750113.jpg "/>


Code:

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

int i = 1; Represents a number between 1-5

Loop is executed when the variable is less than 5 o'clock
while (i<=5) {

The value of the output variable, and add 1 to the variable for the next loop condition to be judged
System.out.println (i);
i++;
}
}
}


Operation Result:

1
2
3
4
5

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

Java Basics---The while (22) of the Java Loop statement

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.