{
  "id": 605896,
  "title": "C# 15 Finally Gets Labeled `break` and `continue`",
  "url": "https://urgent.news/2026/08/11/c-15-finally-gets-labeled-break-and-continue",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-11T22:03:04.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/certosinolab/c-15-finally-gets-labeled-break-and-continue-1h1e"
  },
  "original_language": "en",
  "account": "C# 15 introduces labeled `break` and `continue` statements to more cleanly exit nested loops. In deeply nested loops, using a normal `break` statement only exits the innermost loop, requiring additional mechanisms like Boolean flags or `goto` to exit outer loops. C# 15 allows labeling loops with a name, making it clear which loop should be exited.\n\nFor example, consider searching for a target value within a matrix using nested loops. Without labeled break, a Boolean flag (`found`) is used to indicate when to exit the loops. This flag is only used to propagate a `break` from the inner loop to the outer loop, becoming increasingly awkward as the nesting depth increases. With labeled `break`, a label (e.g., `outer`) is placed directly on the loop, and `break outer;` can be used to exit that labeled loop. This cleanly exits the labeled loop without the need for an extra flag or `goto`.\n\nThe same concept applies to `continue`. Before C# 15, using `continue` in deeply nested loops often required an additional flag to track when to skip the current iteration and move to the next one. With labeled `continue`, a label (e.g., `ordersLoop`) is placed on the loop, and `continue ordersLoop;` can be used to immediately move to the next iteration of the labeled loop.\n\nThis new syntax provides a more intuitive and readable way to handle nested loops, eliminating the need for temporary flags or `goto` statements.",
  "summary": "Nested loops are easy to write. Getting out of them cleanly isn't always as easy. Consider a simple grid search: for ( int row = 0 ; row < grid . Height ; row ++) { for ( int column = 0 ; column < grid . Width ; column ++) { if ( grid [ row , column ]. IsGoal ) { // How do we exit both loops? } } } A normal break isn't enough: break ; It only exits the innermost loop. Until now, C# developers…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}