Java Coding standard / best practices - naming convention for break/continue labels

前端 未结 10 2347
难免孤独
难免孤独 2020-12-15 05:36

Sometimes a labeled break or continue can make code a lot more readable.

OUTERLOOP: for ( ;/*stuff*/; ) {
    //...lots of code

    if ( isEnough() ) break         


        
10条回答
  •  再見小時候
    2020-12-15 06:16

    The convention I've most seen is simply camel case, like a method name...

    myLabel:
    

    but I've also seen labels prefixed with an underscore

    _myLabel:
    

    or with lab...

    labSomething:
    

    You can probably sense though from the other answers that you'll be hard-pushed to find a coding standard that says anything other than 'Don't use labels'. The answer then I guess is that you should use whatever style makes sense to you, as long as it's consistent.

提交回复
热议问题