Sawan Mishra wrote:so return in line9 will never get executed but compiler couldn't catch it
and program compiles successfully why???
Simply put: Because the compiler doesn't check the
body of the loop to see what
might happen to
i (although I believe there
are a few exceptions to that rule).
Question for you: Would
you want to have to write such a compiler? And if so, how would you go about it?
It could certainly be done on a limited basis, but only at the expense of a
lot of stuff that really isn't the business of a compiler. Don't forget that a compiler is basically a
syntax checker, not a checker for "well-formed" logic.
There
are tools around checking if you're doing "anything stupid", but they're MUCH more involved than what the compiler does.
HIH
Winston