# How does "comptime continue" work?

**URL:** <https://ziggit.dev/t/how-does-comptime-continue-work/17941>\
**Category:** Explain\
**Tags:** language, compiler, zig-0-16\
**Created:** [October 13, 2026, 1:45pm UTC](https://ziggit.dev/t/how-does-comptime-continue-work/17941 "2026-10-13T13:45:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tsdtas](https://ziggit.dev/user_avatar/ziggit.dev/tsdtas/32/3512_2.png) [@tsdtas](https://ziggit.dev/u/tsdtas)\
**Post date:** [October 13, 2026, 1:45pm UTC](https://ziggit.dev/t/how-does-comptime-continue-work/17941/1 "2026-10-13T13:45:26Z")

</div>

I’ve been writing some code using inlined loops to introspect type fields.

Removing all the actual logic, I end up with a pattern like this:

```zig
inline for (@typeInfo(T).@"struct".fields) |field| {
    const key = comptime getKey(field);
    if(runtime_map.get(key)) |value| {
        // do something with value
    } 
}

```

Preferring to use `orelse` to short circuit my loops, I got annoyed that this doesn’t work:

```zig
inline for (@typeInfo(T).@"struct".fields) |field| {
    const key = comptime getKey(field);
    const value = runtime_map.get(key) orelse continue;
}

```

```txt
> zig test example.zig
error: comptime control flow inside runtime block

```

Obviously, neither does this:

```zig
inline for (@typeInfo(T).@"struct".fields) |field| {
    const key = comptime getKey(field);
    const value = comptime runtime_map.get(key) orelse continue;
}

```

```zig
> zig test example.zig
error: unable to resolve comptime value

```

Somewhat surprisingly to me, this works:

```zig
inline for (@typeInfo(T).@"struct".fields) |field| {
    const key = comptime getKey(field); 
    const value = runtime_map.get(key) orelse comptime continue;
}

```

I couldn’t find a single instance of it in the language reference, the standard library, or in the Zig codebase, so here I am left wondering about this weird little expression that apparently never occurs in the wild.

Why isn’t `continue` comptime-scoped by default in an inline loop?

What changes about evaluating it when I tack `comptime` in there?

---

<div class="post-metadata">

**Author:** ![00JCIV00](https://ziggit.dev/user_avatar/ziggit.dev/00jciv00/32/1069_2.png) [@00JCIV00](https://ziggit.dev/u/00JCIV00)\
**Post date:** [October 13, 2026, 5:12pm UTC](https://ziggit.dev/t/how-does-comptime-continue-work/17941/2 "2026-10-13T17:12:31Z")

</div>

This has come up a few times. I think a lot of people, myself included, agree that this should work by default. There’s an open issue tracking it at [9524](https://github.com/ziglang/zig/issues/9524) and previous discussion with @mlugg generally agreeing with the idea [here](https://ziggit.dev/t/comptime-control-flow-inside-runtime-block/4962/5).

---

<div class="post-metadata">

**Author:** ![tsdtas](https://ziggit.dev/user_avatar/ziggit.dev/tsdtas/32/3512_2.png) [@tsdtas](https://ziggit.dev/u/tsdtas)\
**Post date:** [October 14, 2026, 8:37am UTC](https://ziggit.dev/t/how-does-comptime-continue-work/17941/3 "2026-10-14T08:37:11Z")

</div>

Thank you for the links! It’s nice seeing this has come up before and I’m just bad at searching. 😅

To be clear, I’m not particularly _surprised_ about `continue` not working. “Inline unrolls the loop so there’s no loop to continue” was just about my intuition for why `continue` didn’t work in the first example.

Why does it then start compiling when you `comptime` evaluate the `continue`?
