return and break

break is used to exit (escape) the for-loop, while-loop, switch-statement that you are currently executing.
return will exit the entire method you are currently executing (and possibly return a value to the caller, optional).

  • break是跳出当前的循环体像是for循环、while循环或是switch语句。

  • return是跳出当前的函数,并且大部分情况会有返回值。

posted @ 2019-09-29 14:47  可爱的黑精灵  阅读(91)  评论(0)    收藏  举报