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