Using “double” as counter variables in loops

The first one will eventually terminate, even if x doesn’t reach exactly 2.0… because it’ll end up being greater than 2.0, and thus break out.

The second one would have to make x hit exactly 1.0 in order to break.

It’s unfortunate that the first example uses a step of 0.25, which is exactly representable in binary floating point – it would have been smarter to make both examples use 0.2 as the step size. (0.2 isn’t exactly representable in binary floating point.)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)