The for Statement

The for Statement

For statement is some Looping statements in PHP

The for statement is used when you know how many times you want to execute a statement or a list of statements.

for (initialization; condition; increment)
{
code to be executed;
}

Note: The for statement has three parameters. The first parameter initializes variables, the second parameter holds the condition, and the third parameter contains the increments required to implement the loop. If more than one variable is included in the initialization or the increment parameter, they should be separated by commas. The condition must evaluate to true or false.

Example

<html>
<body>
<?php
for ($i=1; $i<=5; $i++)
{
echo ” The number is $i<br />”;
}
?>
</body>
</html>

And output is

The number is 1
The number is 2
The number is 3
The number is 4
The number is 5

Leave a comment

6 Comments.

  1. lomr7l7tk1g0l9jm

  2. lomr7l7tk1g0l9jm

  3. Nice post, pretty much nail it for me, cool website!

  4. Cool stuff, thanks for sharing, pretty much on the ball.

  5. Cool stuff, thanks for sharing, pretty much on the ball.

Leave a Reply


[ Ctrl + Enter ]