Feel free to visit Odd or Even Number Code using Java here.
PHP Code
<?php
$i=1;
while($i<=10)
{
echo $i;
if ($i%2==0)
echo " even";
else
echo " odd";
$i++;
}
?>
Refer to the previous article about the while loop for explanation on how to use it. I'll just jump into the conditional statement if which contains the condition wherein we get the remainder of the $i. If the remainder is 0, then it will display even. Otherwise, it will display odd. Just add a break tag before the increment statement to insert new line after each value.
Output
No comments:
Post a Comment