Using continue in a switch statement

后端 未结 7 510
盖世英雄少女心
盖世英雄少女心 2020-12-13 03:29

I want to jump from the middle of a switch statement, to the loop statement in the following code:

while (something = get_something())
{
    swi         


        
7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 03:42

    While technically valid, all these jumps obscure control flow -- especially the continue statement.

    I would use such a trick as a last resort, not first one.

    How about

    while (something = get_something())
    {
        switch (something)
        {
        case A:
        case B:
            do_something();
        }        
    }
    

    It's shorter and perform its stuff in a more clear way.

提交回复
热议问题