How to jump out of a C++ code block?

前端 未结 7 802
无人及你
无人及你 2021-01-04 19:22

This is what I would like to do:

{
    ...
    if(condition)
        break;
    ...
}

This works for a loop. I would like something similar

相关标签:
7条回答
  • 2021-01-04 20:15

    How about

    do
    {
        ...
        if(condition)
            break;
        ...
    }
    while (0);
    

    I don't particularly like this style but I've seen it before. If refactoring is out of the question (could be for a massive block that can break a lot of stuff if changed), this is an option.

    0 讨论(0)
提交回复
热议问题