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
- <span style="FONT-FAMILY:SIMSUN;FONT-SIZE:14PX;" ><span style="FONT-FAMILY:SIMSUN;FONT-SIZE:14PX;" >public class Javabese {
- public static void Main (string[] args) {
- Int J = 3;
- For (int i = 0; i < 5; i++) {
- if (i = = j) {
- continue;
- }
- System.out.println ("i =" + i);
- }
- System.out.pintln ("End of Cycle");
- }
- }</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