TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 230 subscribers
Post #25637 16
I've invented labeled loop breaks

And now I don't believe it wasn't invented before, but I can't find any info on it. How long ago was it invented? Why isn't it used widely or even mentioned anywhere? What are the downsides?
Here's the main idea:

// Keyword - for, while, or do
// Tag - custom loop name
// ... - loop body
#define looptag(keyword, tag, ...)\
keyword(VA
ARGS)\
if(false)\
{\
tag##break: break;\
tag##
continue: continue;\
}\
else\
/Here goes your loop body/

Here is the playground

https://redd.it/1v0s5da
@r_cpp
godbolt.org Compiler Explorer - C++ (x86-64 clang (trunk)) #define loop_tag(keyword, tag, ...)\ keyword(__VA_ARGS__)\ if(false)\ {\ tag##_break: break;\ tag##_continue: continue;\ }\ else #define for_tag(tag, ...)\ loop_tag(for, tag, __VA_ARGS__) #define while_tag(tag…
More from @r_cpp
  1. Sep 26, 2026Token Sequence Injection & Modern Macros: The Most Game-Changing Compile-Time Feature in C…
  2. Sep 25, 2026myStringStream.str("") Considered Harmful Under C++20 I was recently looking at some (rath…
  3. Sep 20, 2026A clever branch free optimization I'm the developer of memlz which is an extremely fast co…
  4. Sep 15, 2026Inside Boost.PolyCollection https://bannalia.blogspot.com/2026/09/inside-boostpolycollecti…
  5. Sep 11, 2026C++26: Standard Library Hardening Experiments https://www.cppstories.com/2026/hardening-ex…
  6. Sep 11, 2026MSVC C++23: constexpr cmath with LLVM Libc https://devblogs.microsoft.com/cppblog/msvc-c23…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →