diff --git a/lib/std/std.zig b/lib/std/std.zig index 940d1ab42eaa..9405fba43531 100644 --- a/lib/std/std.zig +++ b/lib/std/std.zig @@ -92,6 +92,18 @@ pub const x = @import("x.zig"); pub const zig = @import("zig.zig"); pub const start = @import("start.zig"); +/// Use this as a way to increment an index using a for loop. Works with both +/// runtime and comptime integers. +/// +/// ```zig +/// for (range(10)) |_, i| { +/// // 'i' will increment from 0 -> 9 +/// } +/// ``` +pub fn range(len: usize) []const u0 { + return @as([*]u0, undefined)[0..len]; +} + // This forces the start.zig file to be imported, and the comptime logic inside that // file decides whether to export any appropriate start symbols, and call main. comptime {