For the uninformed: counting backwards in a for loop is faster because comparing an unsigned integer against 0 is generally faster than comparing it against any other value.
It also says not to use `for (i >= 0)` because any unsigned integer is >= 0, and the loop will never end.
Oh I remember this from the classic SO post, but it was just presented as a funny trick. I never realized that it solves the issue mentioned in the article and there is a legitimate use-case for post-decrement in the comparison itself.
I don't think it's too clever at all. Notably it works with both signed and unsigned i. Frankly if I see anyone doing anything other than this, they're wrong.
It also says not to use `for (i >= 0)` because any unsigned integer is >= 0, and the loop will never end.
https://stackoverflow.com/questions/1642028/what-is-the-oper...
(Hi Ken!)
http://maulingmonkey.com/brainfuck/
https://github.com/thaliaarchi/bfcorpus/blob/main/ebosman/ma...
Be sure to check out other files in that directory for how the program is assembled.
(Erik Bosman's mandelbrot set is a personal favorite of mine, very useful for benchmarking brainfuck interpreters)
VHDL's array/vector syntax actually works a similar way:
-- gives 0, 1, 2, 3:
for i in 0 to 3 loop
-- gives 3, 2, 1, 0:
for i in 3 downto 0 loop
-- Source - https://stackoverflow.com/a/7642026 -- Posted by Kerrek SB -- Retrieved 2026-10-29, License - CC BY-SA 3.0
For me it does not work because I'd want to use it with values < 0, but the for loop checks for > 0, so I would have to modify that first.