Skip to content

Labelled Blocks

Calibre lets you label a block or loop so you can refer to it by name later.

A label is written with @name between the => and the {} or the statement.

let result := => @basic_block {
42;
};

Labels are especially useful when you want to break out of a specific scope and return a value from it.

In this example, break @basic_block 100 exits the labelled block early and makes the whole block expression evaluate to 100.

let result := => @basic_block {
if true => break @basic_block 100;
42;
};

This gives you a way to structure multi-step logic while still producing a single final value.

Without the labelled break, the block would finish normally and evaluate to its last expression returning 50 instead of 100

let score := => @compute {
let base := 40;
if base > 30 => break @compute 100;
base + 10;
};

Labels are also helpful with nested loops, where you may want to break from an outer loop instead of just the innermost one.

let hit := for x in 0..3 => @outer {
for y in 0..4 => @inner {
if y = 2 => break @outer (x * 10 + y);
if x = 2 => break @inner 99;
} else => {
-1;
};
} else => {
-999;
};

Labelled scopes are useful whenever you want precise control over which block or loop a break should target.