Sagarya Kulkarni wrote:In 1st Code,control comes out of the loop & prints "Hello World"
but in 2nd Code,control goes in infinite loop......Why is it so???
It is actually not an infinite loop -- it is just a ridiculous large loop. The loop will keep decrementing the x value, making the x value more and more negative. This keeps going until the number underflows -- becomes positve again (and a very large number) -- and fails the condition of the do-while loop, hence, exits the loop.
The second case will also eventually print "Hello World". It just have to print all the negative numbers first.
Henry