in reply to limit of for loop!!
The problem is that 0.001 cannot be exactly stored as a floating-point number, just as you cannot store 1/3 exactly as a decimal number. See What Every Computer Scientist Should Know About Floating-Point Arithmetic for details, or search for floating point here on perlmonks.
A way around is to start $a as 22400, add 1 to it at each iteration, and remember to divide by 1000 in the end before using the result (or never divide by 1000, but use the result in a way that accounts for the additional factor)
Note that Perl 6 solves the problem by storing 0.001 as a rational number by default.
use v6; my $a = 22.400; for (1..43) { $a = $a + 0.001; } print "$a\n";
produces 22.443 as output with Rakudo and Niecza.
|
|---|