Slides for P3568R1
break label; and continue label;

Document number:
P3722R0
Date:
2025-05-27
Audience:
SG22
Project:
ISO/IEC 14882 Programming Languages — C++, ISO/IEC JTC1/SC22/WG21
Reply-To:
Jan Schultke <janschultke@gmail.com>
Source:
github.com/Eisenwave/cpp-proposals/blob/master/src/break-continue-label-slides.cow

This document has custom controls:

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

break label;
and
continue label;
P3568R1

Jan Schultke  |  Slides for P3568R1 — break label; and continue label;  |  SG22 Telecon 2025-06-04  |  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 P3568R1 — break label; and continue label;  |  SG22 Telecon 2025-06-04  |  Slide 2

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 P3568R1 — break label; and continue label;  |  SG22 Telecon 2025-06-04  |  Slide 3

Recent history

Graz 2025

Would WG14 like to see a paper changing
loop name syntax at a future meeting?
FNA
6119
  • Conclusion: N3355: for (...) { } syntax wins
    • however, major N3377 concerns unaddressed
  • C++ goes with N3355 syntax
    • also let's try to fix N3377 issues before WG14
Jan Schultke  |  Slides for P3568R1 — break label; and continue label;  |  SG22 Telecon 2025-06-04  |  Slide 4

Unaddressed N3377 concerns

Labels must be unique per function ⇒ problematic for macros:

#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
Jan Schultke  |  Slides for P3568R1 — break label; and continue label;  |  SG22 Telecon 2025-06-04  |  Slide 5

P3568R1 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 P3568R1 — break label; and continue label;  |  SG22 Telecon 2025-06-04  |  Slide 6

Summary

Jan Schultke  |  Slides for P3568R1 — break label; and continue label;  |  SG22 Telecon 2025-06-04  |  Slide 7