Should I use return/continue statement instead of if-else?

前端 未结 13 1885
时光说笑
时光说笑 2020-12-01 10:46

In C, C++ and C# when using a condition inside a function or loop statement it\'s possible to use a continue or return statement as early as possible and g

13条回答
  •  既然无缘
    2020-12-01 10:56

    as other people said, only use return/continue if things are short.

    Personally i only use continue if it is possible to write on one line like:

    while( loopCondition ) {
        if( innerCondition ) continue;
    
        //do other stuff
    }
    

    If it's not possible to write it like this without code getting ugly, then if / else.

提交回复
热议问题