• Image 1
  • Image 2
  • Image 3
  • Image 4
  • Image 5
  • Image 6
  • Image 7




Monday, July 23, 2012

LOOPING IN PHP


Hi.. welcome again in my site at “We Are Knowledge”. Now I want giving you knowledge programming language PHP about ”LOOPING IN PHP”. Previous we was discuss about “CONDITION IN PHP”  using IF and ELSE.

Define from LOOPING is statement continues working until condition fullfiled. For fullfil The program can icrease variable or decrease variable.

LOOPING IN PHP be 3 (three) :
  • FOR
  • WHILE
  • DO WHILE


FOR

Syntax :
for (initial value; limit value; operator increment / decrement)
{
statements to be in the process
}


Ok.. direct to coding. Let’s do it.

Example 1 :
You can copy this coding :

<?php
for ($a = 0; $a <= 100; $a++)
{
echo $a."<br>";
}
?>


Result is 1
2
3
4
100


Next, paste in your notepad. And sava sa type “PHP”

Logic:
$a = 0           >> the initial variable “a” is 0
$a <= 100   >> this is requirement until value a = 100
$a++             >> for increase a value “a” 


Example 2:

You can too copy and paste in your notepad

<?php
for ($a = 0; $a <= 10; $a++)
{
echo "<font size = $a> $a</font>"."<br>";
}
?>

And don’t forget, Save as type “PHP”.

To result :
1
2
3
10

Note : but with size different.



WHILE

Syntax
The initial value
do
{
statements;
operator decrement / increment;
}
While (limit repetition)


Example 3:

You can copy this coding…

<?php
$a = 1;
do
{
echo $a.'<br>';
$a++;
}
while ($a <= 100)
?>

If  it is paste in your notepad and save with save as type “PHP”

And result is
1
2
3
4
100


Logic

$a = 1                          >>  the initial variable a is “1”
Do                                 >> syntax of while. You must write it
echo $a.'<br>'        >> for print. Print same with echo.
$a++;                          >> for increase variable a
while ($a <= 100)  >> program to continues while variable more than “100”


Ok.. just it…
I hope you understanding with my tutorial…
Thanks was visit in my page…
See you later.

No comments:

Post a Comment