Subtle relationships between for, while, do-while, and continue (non-labeled)

Source: Internet
Author: User
The original understanding of continue stays on the surface, roughly thinking that
After executing this statement, the system returns to the iteration header (which is considered to be an import part). I did not expect that there are huge details.

For example: public class test ...{

/***//**
* @ Param ARGs
*/
Public static void main (string [] ARGs )...{
// Todo auto-generated method stub

Int K = 0;
Do ...{
K ++;
If (k <10 )...{
System. Out. println ("do-while:" + k );
Continue;
}
} While (k> 10 );

While (k <10 )...{
System. Out. println ("while:" + k );
If (k <10 )...{
K ++;
Continue;
}
}

For (INT I = 0; I <10; I ++ )...{
System. Out. println ("for:" + I );
If (I <10 )...{
Continue;
}
}

}

}

Returned results:
Do-while: 1
While: 1
While: 2
While: 3
While: 4
While: 5
While: 6
While: 7
While: 8
While: 9
For: 0
For: 1
For: 2
For: 3
For: 4
For: 5
For: 6
For: 7
For: 8
For: 9

Visible:
Do-while (EXC ):
Do -->... --> continue-(skip part of the Code)-> while (EXC) -->...
While (EXC ):
While (EXC) -->... --> continue-(direct)-> while (EXC) -->...
For (A; B; c ):
A --> B -->... --> continue-(direct)-> C --> B -->...

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.