Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.
 help



Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: