#[solved] How to iterate while (true) 0..(modulus N)
1 messages ยท Page 1 of 1 (latest)
could do something like this
while (true) for (0..frame_count) |frame_id| {
_ = frame_id;
// do stuff
};
is that what your intention is?
where is the modulus there?
the goal is to (forever) repeat 0,1,2, 0,1,2, 0,1,2....
thats what my code will do
oh, you achieve the modulus by breaking/ending the for loop. smart ๐ง
yea
that's better even for C, lol
could ofc change the formatting if its confusing, i just wrote it like that so you didnt double indent
@flat adder I just realized we missed something big
The true condition is only checked at each for break โฐ๏ธ ๐
the real code is while (should_not_close()) do_frame();
yea, every while iteration checks for a frame/app ending condition
makes sense
Is the modulus variable unavoidable for this usecase? ๐ค
i might do something like this
frame_id += 1;
if (frame_id > frame_count) frame_id = 0;
but i dont see anything particularly too bad about the original version
its not that its bad, I was just thinking that there might be a way to achieve the variable modification at the while loop syntax or something
you can put it in the continue expression, it accepts a block
while (cond) : ({
frame_id += 1;
if (frame_id > frame_count) frame_id = 0;
}) {
bit ugly though
less ugly with the modulus, right?
๐คทโโ๏ธ
var frameID = 0;
while (condition) : (frameID = (frameID+1) % frames_Len) {
// do thing here
}
```This looks better to me
I guess that'll have to be good enough ๐
ty for the helps, as usual ๐งก ๐
np