3 ms·
> super important in loops to never use "=" as a condition statement, but instead use "<=" (or ">="). Otherwise you might create an infinite loop. Never seems
by bobleeswagger 4y ago
> super important in loops to never use "=" as a condition statement, but instead use "<=" (or ">="). Otherwise you might create an infinite loop.
Never seems a bit strong, it depends on the context. You can use = on int types all day.
- creeble 4y agoBut never with floating point. I think that's the context of the whole article, and should really be the main take-home (which I'm not sure the article gets across clearly enough).
- TheRealPomax 4y agoyou can use it with floats just fine if your condition boundary is a "whole number float", like running from 0.0 to 1.0 in steps of "some small increment". It's only when your boundary has a non-zero fraction that you're going to have to be more careful.
- creeble 4y ago>running from 0.0 to 1.0 in steps of "some small increment". I'm not sure what you mean; those aren't integers (if that's what you mean by "whole number float"): python3 >>> 0.4 == 0.6 - 0.2 False (edit: formatting for python)
- TheRealPomax 4y agofair, that was completely the wrong example.