Created
September 26, 2023 15:08
-
-
Save mikdusan/b61cab3a4e851be3260ec5bed2b8d822 to your computer and use it in GitHub Desktop.
multi optional pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
pub fn main() void { | |
const oa: ?u32 = 0; | |
const ob: ?u32 = 1; | |
const oc: ?u32 = 2; | |
// pattern without "else" codepath | |
outer: { | |
const a = oa orelse break :outer; | |
const b = ob orelse break :outer; | |
const c = oc orelse break :outer; | |
std.log.debug("a={} b={} c={}", .{a,b,c}); | |
} | |
// pattern with "else" codepath | |
outer: { | |
inner: { | |
const a = oa orelse break :inner; | |
const b = ob orelse break :inner; | |
const c = oc orelse break :inner; | |
std.log.debug("a={} b={} c={}", .{a,b,c}); | |
break :outer; | |
} | |
// else codepath | |
std.log.debug("one or more null", .{}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment