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

> Zig does not have a way to iterate through a slice or similar in any way except one-at-a-time forwards. Anything else? You're using a while loop, and you'll enjoy it.

    INCR[U] i FROM 0 TO len(arr) [BY 1] DO ...

    DECR[U] i FROM len(arr) TO 0 [BY 1] DO ...
Although actual BLISS-77 had inclusive semantics for the upper bounds in both forms. Which, on one hand, allows you to write

    DECRU i FROM UINT_MAX TO 0 DO ...
and expect it to Just Work™ (hopefully? No idea if it worked on actual implementation ― but would've been nice, writing the same in e.g. C is kinda annoying; good luck with Golang pre-1.22 and even then, getting that one last iteration is quirky) but on the other hand, inclusive upper bounds require you to write add that "-1" almost everywhere.


That looks a lot like Common Lisp LOOP macro!


Honestly, that's been the standard form of FOR loops since Fortran and Algol-60 until C decided to spice things up.


That may be, but I was born only 40-something years ago, so I haven't had the pleasure to see that other than in Lisp.




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

Search: