Skip to content

Instantly share code, notes, and snippets.

@CurtisFenner
Last active June 22, 2019 21:01
Show Gist options
  • Save CurtisFenner/30f2c0aa76cfd23a4119603c81e31609 to your computer and use it in GitHub Desktop.
Save CurtisFenner/30f2c0aa76cfd23a4119603c81e31609 to your computer and use it in GitHub Desktop.
fn runtime(x: u32) bool {
return x % 2 != 0 and x % 3 != 0 and x % 5 != 0 and x % 7 != 0 and x % 11 != 0;
}
fn loopLegal(comptime arr: var) void {
inline for (arr) |e, i| {
while (true) {
if (!runtime(i)) {
break;
}
std.debug.warn("v: {}, {}\n", i, e);
break;
}
}
}
fn loopIllegal(comptime arr: var) void {
inline for (arr) |e, i| {
if (!runtime(i)) {
continue;
}
std.debug.warn("v: {}, {}\n", i, ie);
}
}
test "Simple" {
loopLegal("Show all the prime indices of this array");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment