# While loop that always executes at least once (do-while loop)?

**URL:** <https://ziggit.dev/t/while-loop-that-always-executes-at-least-once-do-while-loop/13412>\
**Category:** Help\
**Tags:** language\
**Created:** [December 7, 2025, 5:49am UTC](https://ziggit.dev/t/while-loop-that-always-executes-at-least-once-do-while-loop/13412 "2025-12-07T05:49:57Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![npc1054657282](https://ziggit.dev/user_avatar/ziggit.dev/npc1054657282/32/5790_2.png) [@npc1054657282](https://ziggit.dev/u/npc1054657282)\
**Post date:** [December 7, 2025, 6:55am UTC](https://ziggit.dev/t/while-loop-that-always-executes-at-least-once-do-while-loop/13412/7 "2025-12-07T06:55:08Z")

</div>

I [previously discussed](https://ziggit.dev/t/ministry-of-silly-loops/11383/14) the usage implemented with blocks, and @Sze provided a solution based on inline functions that makes fuller use of zls hints:

```zig
pub inline fn do(work: void, @"while": bool) bool {
    _ = work;
    return @"while";
}

pub fn readMailboxInTimeout(
    port: *Port,
    io: std.Io,
    station_address: u16,
    recv_timeout: std.Io.Duration,
    mbx_in: HalfConfiguration,
    mailbox_timeout: std.Io.Duration,
) ReadMailboxInTimeoutError!InContent {
    assert(mbx_in.isValid());

    const deadline = (try std.Io.Clock.Timestamp.now(io, .boot)).addDuration(.{ .clock = .boot, .raw = mailbox_timeout });
    while (do({
        if (try readMailboxIn(
            port,
            io,
            station_address,
            recv_timeout,
            mbx_in,
        )) |in_content| {
            return in_content;
        }
    }, (try std.Io.Clock.Timestamp.now(io, .boot)).compare(.lt, deadline))) {}
    return error.MailboxTimeout;
}

```

---

_[View the full topic](https://ziggit.dev/t/while-loop-that-always-executes-at-least-once-do-while-loop/13412)._
