如何突破一个函数 [英] How to break out of a function
本文介绍了如何突破一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个函数如下:
If I have a function as follows:
void func () {
//...
if (condition) {
break;
}
}
当我使用break它给我一个错误。有没有另一种方法可以使用if条件退出函数并完成正常编译代码?
When I use break it gives me an error. Is there another way to exit a function using an if condition and to complete compiling the code normally?
推荐答案
break用于循环和switch语句。请改用 return
。
break is used in loops and switch statement. use return
instead.
这篇关于如何突破一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文