<p>Sometimes a labeled break or continue can make code a lot more readable. </p>

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

    if ( isEnough() ) break OUTERLOOP;
    //...more code
}
</code></pre>

<p>I was wondering what the common convention for the labels was. All caps? first cap? </p>

[{'answer_id': 15501, 'author': 'RodeoClown', 'author_id': 943, 'author_profile': 'https://Stackoverflow.com/users/943', 'pm_score': 4, 'selected': False, 'text': '<p>The convention is to avoid labels altogether.</p>\n\n<p>There are very, very few valid reasons to use a label for breaking out of a loop. Breaking out is ok, but you can remove the need to break at all by modifying your design a little. In the example you have given, you would extract the \'Lots of code\' sections and put them in individual methods with meaningful names. </p>\n\n<pre><code>for ( ;/*stuff*/; ) \n{\n    lotsOfCode();\n\n    if ( !isEnough() )\n    {\n        moreCode();\n    }\n}\n</code></pre>\n\n<hr>\n\n<p><em>Edit:</em> having seen the actual code in question (<a href="https://stackoverflow.com/questions/15851/refactoring-away-labeled-loops">over here</a>), I think the use of labels is probably the best way to make the code readable. In most cases using labels is the wrong approach, in this instance, I think it is fine.</p>\n'}, {'answer_id': 15644, 'author': 'JProgrammer', 'author_id': 1675, 'author_profile': 'https://Stackoverflow.com/users/1675', 'pm_score': 0, 'selected': False, 'text': '<p>The convetion/best practise would still be not to use them at all and to refactor the code so that is more readable using extract as method.</p>\n'}, {'answer_id': 15658, 'author': 'Craig', 'author_id': 1611, 'author_profile': 'https://Stackoverflow.com/users/1611', 'pm_score': 5, 'selected': True, 'text': '<p>If you have to use them use capitals, this draws attention to them and singles them out from being mistakenly interpreted as "Class" names.  Drawing attention to them has the additional benefit of catching someone\'s eye that will come along and refactor your code and remove them. ;)</p>\n'}, {'answer_id': 15663, 'author': 'Michael Neale', 'author_id': 699, 'author_profile': 'https://Stackoverflow.com/users/699', 'pm_score': 0, 'selected': False, 'text': "<p>They are kind of the goto of Java - not sure if C# has them. I have never used them in practice, I can't think of a case where avoiding them wouldn't result in much more readable code. </p>\n\n<p>But if you have to- I think all caps is ok. Most people won't use labelled breaks, so when they see the code, the caps will jump out at them and will force them to realise what is going on. </p>\n"}, {'answer_id': 15665, 'author': 'RodeoClown', 'author_id': 943, 'author_profile': 'https://Stackoverflow.com/users/943', 'pm_score': 0, 'selected': False, 'text': "<blockquote>\n<p>I know, I should not use labels.</p>\n<p>But just assume, I have some code, that could gain a lot in readability from labeled breaks, how do I format them.</p>\n</blockquote>\n<p>Mo, your premise is wrong.\nThe question shouldn't be 'how do I format them?'</p>\n<p>Your question should be 'I have code that has a large amount of logic inside loops - how do I make it more readable?'</p>\n<p>The answer to that question is to move the code into individual, well named functions. Then you don't need to label the breaks at all.</p>\n"}, {'answer_id': 15894, 'author': 'izb', 'author_id': 974, 'author_profile': 'https://Stackoverflow.com/users/974', 'pm_score': 2, 'selected': False, 'text': "<p>The convention I've most seen is simply camel case, like a method name...</p>\n\n<pre><code>myLabel:\n</code></pre>\n\n<p>but I've also seen labels prefixed with an underscore</p>\n\n<pre><code>_myLabel:\n</code></pre>\n\n<p>or with lab...</p>\n\n<pre><code>labSomething:\n</code></pre>\n\n<p>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.</p>\n"}, {'answer_id': 15939, 'author': 'Marcus Downing', 'author_id': 1000, 'author_profile': 'https://Stackoverflow.com/users/1000', 'pm_score': 5, 'selected': False, 'text': '<p>I don\'t understand where this "don\'t use labels" rule comes from. When doing non-trivial looping logic, the test to break or continue isn\'t always neatly at the end of the surrounding block.</p>\n\n<pre><code>outer_loop:\nfor (...) {\n  //  some code\n  for (...) {\n    //  some code\n    if (...)\n      continue outer_loop;\n    //  more code\n  }\n  //  more code\n}\n</code></pre>\n\n<p>Yes, cases like this do happen all the time. What are people suggesting I use instead? A boolean condition like this?</p>\n\n<pre><code>for (...) {\n  //  some code\n  boolean continueOuterLoop = false;\n  for (...) {\n    //  some code\n    if (...) {\n      continueOuterLoop = true;\n      break;\n    }\n    //  more code\n  }\n  if (continueOuterLoop)\n    continue;\n  //  more code\n}\n</code></pre>\n\n<p><strong>Yuck!</strong>  Refactoring it as a method doesn\'t alleviate that either:</p>\n\n<pre><code>boolean innerLoop (...) {\n  for (...) {\n    //  some code\n    if (...) {\n      return true;\n    }\n    //  more code\n  }\n  return false;\n}\n\nfor (...) {\n  //  some code\n  if (innerLoop(...))\n    continue;\n  //  more code\n}\n</code></pre>\n\n<p>Sure it\'s a little prettier, but it\'s still passing around a superfluous boolean. And if the inner loop modified local variables, refactoring it into a method isn\'t always the correct solution.</p>\n\n<p>So why are you all against labels? Give me some solid reasons, and practical alternatives for the above case.</p>\n'}, {'answer_id': 15944, 'author': 'SCdF', 'author_id': 1666, 'author_profile': 'https://Stackoverflow.com/users/1666', 'pm_score': 1, 'selected': False, 'text': '<p>wrt <a href="https://stackoverflow.com/questions/15481/java-coding-standard-best-practices-labeled-brakecontinue#15939">sadie\'s code example</a>:</p>\n\n<p>You gave </p>\n\n<pre><code>outerloop:\nfor (...) {\n  //  some code\n  for (...) {\n    //  some code\n    if (...)\n      continue outerloop;\n    //  more code\n  }\n  //  more code\n}\n</code></pre>\n\n<p>As an example. You make a good point. My best guess would be:</p>\n\n<pre><code>public void lookMumNoLabels() {\n  for (...) {\n    // some code\n    doMoreInnerCodeLogic(...);\n  }\n}\n\nprivate void doMoreInnerCodeLogic(...) {\n   for (...) {\n      // some code\n      if (...) return;\n   }\n}\n</code></pre>\n\n<p>But there would be examples where that kind of refactoring doesn\'t sit correctly with whatever logic you\'re doing.</p>\n'}, {'answer_id': 17643, 'author': 'Mo.', 'author_id': 1870, 'author_profile': 'https://Stackoverflow.com/users/1870', 'pm_score': 1, 'selected': False, 'text': '<p>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.</p>\n\n<p>But since they are so rare, in my opinion it is best, to think twice whether they are really the right tool.</p>\n\n<p>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)</p>\n'}, {'answer_id': 17756, 'author': 'Anders Sandvig', 'author_id': 1709, 'author_profile': 'https://Stackoverflow.com/users/1709', 'pm_score': 3, 'selected': False, 'text': "<p>Sun's Java code style seem to prefer naming labels in the same way as variables, meaning camel case with the first letter in lower case.</p>\n"}]
['https://Stackoverflow.com/questions/15481', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1870/']