Hello Folks,
I used a piece of code to test the square root of some numbers in a JAVA application using 'DO' 'WHILE' functions and everything worked well. So, I decided to do the same thing using PHP. I have tried both the 'WHILE' and 'DO WHILE' functions in PHP. They both work fine except that I get an extra number. Could someone have a look at my code and see what I am doing wrong, please?
When I run the code above, I get the output below.Code:<?php $i = 1; while($i <=5){ echo "The square root of " .$i." is " .$i*$i ."<br/>"; $i++; } echo $i; ?>
Why do I get 6 which is an extra number added to it?Code:The square root of 1 is 1 The square root of 2 is 4 The square root of 3 is 9 The square root of 4 is 16 The square root of 5 is 25 6
Any help will be much appreciated.


Reply With Quote