Is it strange to use the while loop like this? PHPcode $ pnum91; $ randNum0; while ($ pnum & gt; 18) {$ randNum $ pnum2; if ($ randNum & lt; 18) {is it strange to use the while loop like this?
PHP code
$ Pnum = 91; $ randNum = 0; while ($ pnum> 18) {$ randNum = $ pnum/2; if ($ randNum <18) {break ;}} echo $ randNum; // Display 45.5
My intention is to get a number smaller than 18,
However, what we get is 45.5?
Where is the error?
------ Solution --------------------
While is used as follows:
$ Pnum = 91;
While ($ pnum> = 18 ){
$ Pnum/= 2;
}
Echo $ pnum;
------ Solution --------------------
A dead loop cannot exist.
My intention is to get a number smaller than 18 ?? What are your requirements? Confused
PHP code
$ Pnum = 91; $ randNum = 0; while ($ pnum> 18) {$ randNum = $ pnum/2; if ($ randNum <18) {break;} echo $ randNum; I don't know what you want to do if you divide it by 2...