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

前端 未结 10 2361
难免孤独
难免孤独 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:13

    As labels are so rarely useful, it appears, that there is no clear convention. The Java language specification has one example with labels and they are in non_cap.

    But since they are so rare, in my opinion it is best, to think twice whether they are really the right tool.

    And if they are the right tool, make them all caps so that other developers (or yourself later on) realize them as something unusual right away. (as Craig already pointed out)

提交回复
热议问题