Skip to content

Commit 814b2ec

Browse files
committed
add labeled
1 parent c08e063 commit 814b2ec

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

labeled/for.zig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const print = @import("std").debug.print;
2+
3+
pub fn main() void {
4+
outer: for (1..100) |_| {
5+
for (1..10) |i| {
6+
print("Value: {}\n", .{i});
7+
if (i == 4) {
8+
print("Break\n", .{});
9+
break :outer;
10+
}
11+
}
12+
}
13+
}

labeled/readme.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Labeled
2+
3+
```bash
4+
$ zig run while.zig
5+
Value: 0
6+
Value: 1
7+
Value: 2
8+
Value: 3
9+
Break
10+
```
11+
12+
```bash
13+
$ zig run for.zig
14+
Value: 0
15+
Value: 1
16+
Value: 2
17+
Value: 3
18+
Break
19+
```

labeled/while.zig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const print = @import("std").debug.print;
2+
3+
pub fn main() void {
4+
outer: while (true) {
5+
var val: u16 = 0;
6+
7+
while (true) {
8+
print("Value: {}\n", .{val});
9+
val += 1;
10+
11+
if (val == 4) {
12+
print("Break\n", .{});
13+
break :outer;
14+
}
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)