Umair Y.

asked • 08/07/15

PHP Loop Help

Write a small program (Code) in PHP language using for loop which prints from 1 to 100.

Anthony F.

SYNTAX
 
for (init; condition; increment)
{
     code to be executed
}
 
The “for” loop holds three parameters. The init can be any piece of code that needs to be executed once at the beginning of the loop. In most cases init is used to set a counter. The condition is used to evaluate if the loop needs to continue. The evaluation is done for each loop iteration. If the evaluation is FALSE, the loop will end.
 
<html>
<body>

<?php
for ($x=1; $x<=100; $x++)
{
echo "Number is " . $x . "<br />";
}
?>

</body>
</html>
 
The output should be:
Number is 1
Number is 2
Number is 3
Number is 4
Number is 5
       .
       .
       .
Number is 100.
 
 
Report

11/04/15

1 Expert Answer

By:

Stefan R. answered • 03/10/20

Tutor
5.0 (625)

Senior PHP developer with 10+ years of experience

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.