en.javascript.info/1-js/4-data-structures/2-number/4-endless-loop-error/solution.md
2016-03-06 00:59:16 +03:00

17 lines
No EOL
368 B
Markdown

That's because `i` would never equal `10`.
Run it to see the *real* values of `i`:
```js run
let i = 0;
while (i < 11) {
i += 0.2;
if (i > 9.8 && i < 10.2) alert( i );
}
```
None of them is exactly `10`.
Such things happen because of the precision losses when adding fractions like `0.2`.
Conclusion: evade equality checks when working with decimal fractions.