logoalt Hacker News

the__alchemistlast Friday at 10:39 PM2 repliesview on HN

I just learned this one, and am gradually starting to use it! It applies for loops too. I saw it in ChatGPT code, and had to stop and look it up. Rust is a big language, for worse and for better.


Replies

kibwenyesterday at 12:49 AM

I wouldn't call Rust "a big language" because of labeled break. This is a pretty standard language feature, you can do the same in C (and therefore C++), Go, Javascript, Java, C#...

show 1 reply
tialaramexyesterday at 1:33 AM

  break 'label value;
... is something to be used very sparingly. I reckon I write a new one about once a year.

Very often if you think harder you realise you didn't want this, you should write say, a function (from which you can return) or actually you didn't want to break early at all. Not always, but often. If you write more "break 'label value" than just break then you are almost certainly Doing It Wrong™.

show 1 reply