How to break out of a function

Shadi picture Shadi · Jun 10, 2011 · Viewed 93.4k times · Source

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?

Answer

Headshota picture Headshota · Jun 10, 2011

break is used in loops and switch statement. use return instead.