return false后是否需要break
在 bool 函数内的 switch 语句中我有这个。我是否添加了中断,或者是否暗示我在这方面非常糟糕。
case Stop:
default:
return false;
//break;??????
In a switch statement inside a bool function I have this. Do I add break or is it implied I am very bad at this.
case Stop:
default:
return false;
//break;??????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
否,如果您从
default
返回,则不需要 case break 语句。您必须仅在所有要操作的情况后添加break语句并停止开关的工作,否则默认操作从函数返回。
No if you return from
default
case break statement isn't necessary there.You must add break statement only after all your cases which you want to operate and stop switch's work, otherwise default is operated returning from function.
不需要中断,因为
return
将是函数中执行的最后一条语句。No break is required as
return
will be the last statement executed in the function.它不是“隐含的”,但由于代码永远不会到达那里,因此您不必编写
break;
。It is not "implied", but since the code will never get there, you don't have to write
break;
.只是多余,
return
就够了。It's just redundant,
return
is enough.如果程序前面有 return 语句,则程序执行将永远不会到达break 语句。
program execution will never reach at the break statement if it has return statement before it.
返回后,程序将不会到达中断处,因此您可以从那里删除该语句。
After return the program will not reach the break so you can remove the statement from there.