While loop and do while loop

Source: Internet
Author: User

1. The while loop is to write the repeated actions in the code into a more concise and intuitive statement.

2. Do While is literally recycled first.

Similarities:

① It is a loop structure. "While (loop condition)" is used to indicate the loop condition and braces are used to enclose the loop operation.

Differences:

① The syntax is different. Compared with the while loop, The do while loop places the while keyword and the loop condition behind it, and adds a do keyword and a semicolon.

② The execution order is different. The while loop first judges and then executes; The do while loop first executes and then judges.

③ If the first loop condition is not met, the while loop will not be executed once, And the do while loop will be executed at least once no matter under any circumstances.

 

While loop and do while loop

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.