Java: Using while () and do....while with for ()

Source: Internet
Author: User
while (true)

{

     操作;

}

And

do{

     操作;

}while (True)

It acts on the loop of operation in curly braces, so long as the condition is judged as "true", it can be cycled forever.

So write to the loop condition of the operation, otherwise it will die loop, cause the subsequent operation cannot execute.

There is a difference between the two while:

while () is first judged in execution,

Do{...} while () is performed first in the judgment.

The for (variable initial value; cyclic condition; variable change) is based on the while and adds the control of the number of cycles.

Example:

for (i==0;i<100;i++)

{

SYSTEM.OUT.PRINTLN ("Study hard!") ")

}

Result: Show "study hard!" "Shown 100 times.

Tip: In the case of uncertain cycle times, using while is more appropriate, but for the number of cycles known to use for more convenient.

Java: Using while () and do....while with for ()

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.