The difference between a for loop and a do......while

Source: Internet
Author: User

The difference between a for loop and a do......while

In fact, in the functional, there is no difference, because the for loop can implement the Do......while can also be implemented, Do......while can implement for can also be implemented.

But that's what we do when we use the For loop:

for (int i;i>0:i++)

{

Circulation body;

}

And the do......while is like this:

int i=0;

do{

Circulation body;

}

while (I<10)

This is the difference, for the variable of the loop can be defined in the function body, and when the loop ends, the variable disappears and does not occupy memory.

And do......while, the defined variable is global, exists forever, and consumes memory.

Of course, there is nothing on the PC, but if used on the phone, memory is very valuable, can save the province.

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.