Home 19. breaking from labeled blocks
Post
Cancel

19. breaking from labeled blocks

As of 1.65, it is possible to label plain block expression and terminate that block early.

1
2
3
4
5
6
7
8
9
10
11
let result = 'block: {
    let result = 20i32;
    if result < 10 {
        break 'block 1;
    }
    if result > 10 {
        break 'block 2;
    }
    3
};
assert_eq!(result, 2);
This post is licensed under CC BY 4.0 by the author.