Controlling Execution

Return
The  return  keyword has two purposes:  It specifies what value a method will return  (if it doesn’t have a void return value) and  it causes the current method to exit, returning that value
If you do not have a  return statement in a method that returns  void, there’s an implicit  return at the end of that method, so it’s not always necessary to include a  return statement. However, if your method states it will  return anything other than  void, you must ensure every code path will  return a value. 
Break只能跳出一重循环(经测试验证)。
The switch statement requires a selector that evaluates to an integral value, such as int or char.
The infamous “goto”
Although  goto is a reserved word in Java, it is not used in the language; Java has no  goto. However, it does have something that looks a bit like a jump tied in with the  break and  continue keywords.  It’s not a jump but rather a way to break out of an iteration statement. The reason it’s often thrown in with discussions of goto is because it uses the same mechanism:  a label
The only place a label is useful in Java is right before an iteration statement.And that means 
right before—it does no good to put any other statement between the label and the iteration.  And the sole reason to put a label before an iteration is if you’re going to nest another iteration or a switch (which you’ll learn about shortly) inside it. That’s because the break and continue keywords will normally interrupt only the current loop , but when used with a label, they’ll interrupt the loops up to where the label exists.(使用lable的原因是需要跳出多重循环,而break与continue只能跳出单重循环)
The same rules hold true for while: 
1.   A plain  continue goes to the top of the innermost loop and continues. 
2.  A  labeled continue goes to the label and reenters the loop right after that label. 
3.  A  break “drops out of the bottom” of the loop. 
4.  A  labeled break drops out of the bottom of the end of the loop denoted by the label.   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值