# New in Rust 1.65, break from labeled blocks

**URL:** <https://forum.crystal-lang.org/t/new-in-rust-1-65-break-from-labeled-blocks/5069>\
**Category:** News\
**Created:** [November 3, 2022, 11:31pm UTC](https://forum.crystal-lang.org/t/new-in-rust-1-65-break-from-labeled-blocks/5069 "2022-11-03T23:31:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jzakiya](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/jzakiya/32/278_2.png) [@jzakiya](https://forum.crystal-lang.org/u/jzakiya)\
**Post date:** [November 3, 2022, 11:31pm UTC](https://forum.crystal-lang.org/t/new-in-rust-1-65-break-from-labeled-blocks/5069/1 "2022-11-03T23:31:08Z")

</div>

I just saw the announcement of the release of the new Rust 1.65.  
A new feature is: **`break from labeled blocks`**

> **[Redirect](https://blog.rust-lang.org/2022/11/03/Rust-1.65.0.html)**

### `break` from labeled blocks

Plain block expressions can now be labeled as a `break` target, terminating that block early. This may sound a little like a `goto` statement, but it’s not an arbitrary jump, only from within a block to its end. This was already possible with `loop` blocks, and you may have seen people write loops that always execute only once, just to get a labeled `break`.

Now there’s a language feature specifically for that! Labeled `break` may also include an expression value, just as with loops, letting a multi-statement block have an early “return” value.

```auto
let result = 'block: {
    do_thing();
    if condition_not_met() {
        break 'block 1;
    }
    do_next_thing();
    if condition_not_met() {
        break 'block 2;
    }
    do_last_thing();
    3
};

```

This reminded me of a thread I started in Feb 2022: **Elegant breaking from nested loops**.

> [@Elegant breaking from nested loops](https://forum.crystal-lang.org/t/elegant-breaking-from-nested-loops/4337):
>
> I have two nested loops like this: loop1 do ... loop2 do ... break if cond ... end ... end Here, the break just gets me out of the inner loop2 but I want to get out of both. I have a cludge way of doing that, but does Crystal provide an elegant way to break out of both?

I find it interesting (funny) that the pedantic Rust devs seemingly folded to pressure to add this,  
or maybe it was just a logical addition after surfeit technical analysis. 😄

---

<div class="post-metadata">

**Author:** ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)\
**Post date:** [November 4, 2022, 4:58am UTC](https://forum.crystal-lang.org/t/new-in-rust-1-65-break-from-labeled-blocks/5069/2 "2022-11-04T04:58:40Z")

</div>

Check the following code basically meet same issue with you.

> [@Error: can't use variable name 'some\_name' inside assignment to variable 'some\_name'](https://forum.crystal-lang.org/t/error-cant-use-variable-name-some-name-inside-assignment-to-variable-some-name/4965/3):
>
> It works! def keys keys = [] of String \_keys = uninitialized (Array(String), Node?) -\> \_keys = -\>(arr : Array(String), node : Node?) do return if node.nil? \_keys.call(arr, node.left) arr \<\< node.key unless node.key == "" \_keys.call(arr, node.right) end \_keys.call(keys, @root) keys end Although, i have to use return if node.nil? instead next if node.nil?(in ruby), return return to the \_keys.call(...), not the method keys, this is expected,…

---

<div class="post-metadata">

**Author:** ![Bonarc](https://avatars.discourse-cdn.com/v4/letter/b/7ab992/32.png) [@Bonarc](https://forum.crystal-lang.org/u/Bonarc)\
**Post date:** [November 5, 2022, 9:04pm UTC](https://forum.crystal-lang.org/t/new-in-rust-1-65-break-from-labeled-blocks/5069/3 "2022-11-05T21:04:32Z")

</div>

I remember using an independent language called Nelua that let you create arbitrary blocks with scopes using do…end and I thought it was a nice touch

```crystal
do
    #some code
end

```

I’m not sure if it would be easy for crystal to implement based on how it currently uses them, or difficult.

---

<div class="post-metadata">

**Author:** ![chikega](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/chikega/32/1407_2.png) [@chikega](https://forum.crystal-lang.org/u/chikega)\
**Post date:** [December 21, 2023, 8:07pm UTC](https://forum.crystal-lang.org/t/new-in-rust-1-65-break-from-labeled-blocks/5069/4 "2023-12-21T20:07:40Z")

</div>

> [@Bonarc](#):
>
> Nelua

[Nelua](https://nelua.io) looks like a very cool Lua variant. My son is learning another Lua variant ‘Luau’ for Roblox. 🤩
