Meet java-3.2 return break continue from scratch

Source: Internet
Author: User

In this section we say that the return break continue is directly identical and different.

1. Same

Are jumping out of the loop.

Package Com.ray.ch03;public class Test {public static void main (string[] args) {System.out.println ("-------with Break-------"), for (int i = 0; i <, i++) {if (i = = 5) {break;} System.out.println (i);} System.out.println ("-------with continue-------"), for (int i = 0; i <; i++) {if (i = = 5) {continue;} System.out.println (i);} System.out.println ("-------with return-------"), for (int i = 0; i <; i++) {if (i = = 5) {return;} System.out.println (i);} System.out.println ("-------If End?-------");}}

Output:

-------with break-------
0
1
2
3
4
-------with continue-------
0
1
2
3
4
6
7
8
9
-------with return-------
0
1
2
3
4

As you can see from the output, all three are jumping out of the loop, but this leads to the different points below.


2. Different points

Keep looking at the results above.

Break: Jump out when i==5, no longer loop output

Continue: Jump out while i==5, but continue with other loops

Return: Out of the way when i==5, no longer executes any code, leads to the last sentence output is not executed.


Summary: This section briefly describes the same and different continue of the return break directly.


This chapter is here, thank you.

-----------------------------------

Directory


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Meet java-3.2 return break continue from scratch

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.