| ▲ | MaulingMonkey a day ago |
| I prefer: const size_t n = 10;
for (size_t i = n; i --> 0;) {
std::cout << i << "\n";
}
|
|
| ▲ | hedgehog a day ago | parent | next [-] |
| That's a certain kind of taste... I checked out your home page, game dev, check, and this work of art is worth linking (no irony, I love it): http://maulingmonkey.com/brainfuck/ |
| |
| ▲ | omoikane a day ago | parent [-] | | That looks like the brainfuck mandelbrot set by Erik Bosman, but the example is missing the header line with the credit. The one I saw came from here: 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) |
|
|
| ▲ | ranger_danger a day ago | parent | prev [-] |
| Cute but wouldn't work with ssize_t :) 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 |
| |
| ▲ | fourthark a day ago | parent [-] | | Does work with ssize_t, just not necessary. | | |
| ▲ | ranger_danger a day ago | parent [-] | | Depends on your definition of "work". 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. | | |
| ▲ | MaulingMonkey a day ago | parent [-] | | If you want -3 -2 -1 0 and +3 +2 +1 0 from the same operation, you'll need something more complicated (either some nonsense to give you a signed stride/step value among other things — or perhaps just writing the damn loop twice instead of getting too clever.) However, if you just want -1 to not iterate down to `std::numeric_limits<ssize_t>::min()` — and then invoke undefined behavior by signed integer underflow if `i` happens to be `ssize_t` instead of `size_t` — I'll note that the `i --> 0` will terminate immediately, unlike `i --` as otherwise seen. (unless you feed it `min()` exactly. Then it'll underflow a signed integer before the comparison, so that's still undefined behavior.) |
|
|
|