Use of break, continue and return in the for loop in Java

Introduction: when using a loop, it is often confused when there are break, continue and return in the loop. Today, I specially sorted it out for later use

Print results:

Print results:

Print results:

End of inner for loop

Print results:

Print results:

From the above results, In general, break is to jump out of the current loop (the closest loop) to continue the outer loop; continue ends the current loop. The code after continue does not execute and continues the following loop. That is, it is still in the same loop. Different from break, break jumps to the outer loop; return terminates the current method and the code behind the method will not execute. These are just my rough ideas Test results, if you have a better supplement, please leave a message, and I will modify it accordingly.

summary

The above is what Xiaobian introduced to you about the use of break, continue and return in Java in the for loop. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>