4 ms·
This form is basically always used for enumeration. Might as well just do (x != y); unless you're specifically looking to guard against erroneous bitflips that
by rgbgraph 3y ago
This form is basically always used for enumeration.
Might as well just do (x != y); unless you're specifically looking to guard against erroneous bitflips that would be caught by the prior (x < y), but not the former. But at that point -- it's likely your result is going to be garbage.
In essence they're the same; but one you never have to think about whether you're using it correctly.
Can anyone find a reason not to swap out (x < y) for (x != y)?
- rowanG077 3y ago`<` communicates the intent way better. It also more readable Example: The loop should run as long as the counter is smaller than 10. `i /= 10` achieves the same thing but communicates something very different. It implies `i` may be changed inside the loop to become larger than 10. The condition itself implies a larger valid state space. It's a moot point anyway. Modern languages have much better looping constructs.
- olkingcole 3y ago(If I'm understanding correctly) one example is if have two places where you x++ in the loop, so if you make an error in there you might end up hitting both of them and incrementing from y-1 to y+1.
- urthor 3y ago[flagged]
- rincebrain 3y agoIf you have a bug and produce x+=2, you never terminate? One might argue corrupting much larger swathes of memory is better from a "fail-fast" perspective, but there's always tradeoffs.