Tuesday, January 26, 2016

FOR LOOP PHP: Display Numbers Using For Loop in PHP

For loop is used if you already know how many times your code will be executed.

Syntax
for(init;condition;increment/decrement)
{
 statement
}
init - initialization of your variable/counter
condition - test whether the statement is false to be able to continue execution. If true, then the loop stops.
increment/decrement - adds/subtracts a certain value

Let's say you want to display numbers from 1 to 10 using a for loop. The following is the code.

PHP Code

<?php
for ($i=1;$i<=10;$i++)
{
echo $i;
echo "<br>";
}
?>

Output















FOR LOOP PHP: Display Numbers Using For Loop in PHP

FOR LOOP PHP: Display Numbers Using For Loop in PHP Rating: 4.5 Diposkan Oleh: Emoblazz

0 comments:

Post a Comment