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

前端 未结 7 880
无人及你
无人及你 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:05

    Here just some additional possibilities:

    for(..)
    {
        continue;//next loop iteration
    }
    
    void mymethod()
    {
        ...
        return;
        ...
    }
    

    Probably you should create sub-methods for the problematic block of code were you wanted to use goto and leave the block of code by the usage of return.

提交回复
热议问题