Hacker News new | ask | show | jobs
by ismailmaj 51 days ago
branchless for loop for funsies

  for (fn, n) = {
    stop = void (i) {}
    run  = void (i) { fn(i); go(i + 1) }
    go   = void (i) { *((i < n) * &run + (i >= n) * &stop)(i) }
    go(0)
  }
Or you could write all the implementations for each possible n and dispatch through a registry.