The difference between keywords continue, break, and return in Java

Source: Internet
Author: User

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. http://blog.csdn.net/shineflowers/article/details/41747149

The difference between keywords continue, break, and return in Java:

Continue: Jump out of this loop to continue the next cycle

Break: Jumps out of the loop body and resumes execution of the function body outside the loop

Return: Jumps out of the entire function body, the part behind the function body no longer executes

There is code for the truth:

[Java]View PlainCopy
  1. <span style="FONT-FAMILY:SIMSUN;FONT-SIZE:14PX;" ><span style="FONT-FAMILY:SIMSUN;FONT-SIZE:14PX;" >public class Javabese {
  2. public static void Main (string[] args) {
  3. Int J = 3;
  4. For (int i = 0; i < 5; i++) {
  5. if (i = = j) {
  6. continue;
  7. }
  8. System.out.println ("i =" + i);
  9. }
  10. System.out.pintln ("End of Cycle");
  11. }
  12. }</span></span>

Printing results are:

i = 0

i = 1

i = 2

i = 4

End of cycle

If it is break, the print result is:

i = 0

i = 1

i = 2

End of cycle

If it is return, the result of the printing is:

i = 0

i = 1

i = 2

The difference between keywords continue, break, and return in Java

Related Article

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.