write a program in php to generate first 20 natural numbers?
Answers
for( $i=1; $i<=20; $i++ )
{
echo $i;
echo "<br>";
}
PHP for loop is same as C program.
$i is the variable which will get initialized to 1 in the beginning of for loop.
It loops until $i becomes equal to 20. (First 20 natural numbers).
First Echo statement prints the value of $1.
Second Echo prints the new line
The loop increments the $1 value to next level.
Above program prints first 20 natural numbers.
Answer:
Explanation:
The program in PHP to generate the first 20 natural numbers is:
Using For Loop:
for($i = 1; $i<=20; $i++)
{
echo $i;
echo ""<br>"";
}
Using While Loop:
while($i <= 20)
{
echo $i. '<br>';
$i = $i + 1;
}
hypertext preprocessor is a kind of processor which is an open source genera purose software a kind of scripting language that is especially suited as a part of major web development technology.