Slides for P3568R2
break label; and continue label;

Document number:
P3722R1
Date:
2026-06-08
Audience:
SG22
Project:
ISO/IEC 14882 Programming Languages — C++, ISO/IEC JTC1/SC22/WG21
Reply-To:
Jan Schultke <janschultke@gmail.com>
Source:
break-continue-label-slides.cow

This document has custom controls:

  • ,  ↓ : go to the next slide
  • ,  ↑ : go to previous slide

break label;
and
continue label;
P3568R2

Jan Schultke  |  Slides for P3568R2 — break label; and continue label;  |  EWG Brno 2026-06  |  Slide 1

Introduction

C2y now supports break and continue with a label (N3355):

outer: for (int i = 0; i < N; ++i) for (int j = 0; j < M; ++j) if (/* ... */) break outer; // OK, break targets "outer"
Jan Schultke  |  Slides for P3568R2 — break label; and continue label;  |  EWG Brno 2026-06  |  Slide 2

C++26 Expansion Statements

Breaking out of loop from expanded statement:

outer: for (const auto& tuple : list_of_tuples) template for (const auto& e : tuple) if (/* ... */) break outer;

Possible future direction: expand case labels:

outer: switch (/* ... */) { template for (constexpr int N : cases) case N: visit<N>(); break outer; }
Jan Schultke  |  Slides for P3568R2 — break label; and continue label;  |  EWG Brno 2026-06  |  Slide 3

Recent history — Hagenberg 2025

EWG likes syntax N3355: for (...) { }
SFFNASA
416595
EWG likes syntax for N3377 (...) { }
SFFNASA
713558
If C has it, we are interested in this feature too.
SFFNASA
1621523

Conclusion

Let WG14 figure out syntax;
we'll copy the feature into C++.
Jan Schultke  |  Slides for P3568R2 — break label; and continue label;  |  EWG Brno 2026-06  |  Slide 4

N3658: Simplified lexical scope for labels

Labels must be unique per function ⇒ problematic for macros and nesting:

#define MACRO() \ outer: for (/* ... */) \ for (/* ...*/) break outer MACRO(); // OK MACRO(); // error: duplicate "outer" // Also, nested reuse of names impossible: outer: for (/* ... */) inner: for (/* ... */) outer: for (/* ... */) inner: for (/* ... */) // error

N3658 solution: drop label restrictions, error on goto duplicate;

Jan Schultke  |  Slides for P3568R2 — break label; and continue label;  |  EWG Brno 2026-06  |  Slide 5

Recent history — WG14

Graz 2025

Would WG14 like to see a paper changing loop name syntax at a future meeting?
FNA
6119

Brno 2025

Would WG14 like to adopt something along the lines of N3658 into C2y?
FNA
1871
Jan Schultke  |  Slides for P3568R2 — break label; and continue label;  |  EWG Brno 2026-06  |  Slide 6

P3568R2 strategy

label: label: while (true) break label; // OK label: for (/* ... */) continue label; // OK goto label; // error: jump to duplicate label while (true) break label; // error: break of unrelated loop
Jan Schultke  |  Slides for P3568R2 — break label; and continue label;  |  EWG Brno 2026-06  |  Slide 7

Summary

Jan Schultke  |  Slides for P3568R2 — break label; and continue label;  |  EWG Brno 2026-06  |  Slide 8