How to break out of a function
问题 If I have a function as follows: void func () { //... if (condition) { break; } } 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? 回答1: break is used in loops and switch statement. use return instead. 回答2: use return; : if(/*condition*/) { return; } 回答3: Try to use 'return' in place of break when you want to run rest of code normally. Use 'break' in case of switch or for loop for normal execution