PHP Loop ~ PinoySourceCode

Friday, April 25, 2014

PHP Loop

Loop execute some statement many times till the condition is fullfill.

There are three type or loops. these loops do same work execute statement many times.
  • While loop
  • Do While loop
  • For Loop
while loop

while loops are the simplest type of loop in PHP. They behave just like their C counterparts. The basic form of a while statement is:
===========================
while (expr)
    statement
===========================
In the while loop it first check the condition then body of the loop will be executed many times untill the condition is fullfill.

Syntax
===========================
while (condition)
 {
  Code here.
 }
===========================
Exercise 1:
===========================
<?php
$i=1;
while($i<=5)
  {
  echo "Number".$i;
  $i++;
  }

?> Output

Number 1

Number 2

Number 3

Number 4

Number 5

do while

Exercise 2:

===========================
<?php

$i=1;
do
  {
  echo "Number".$i;
  $i++;
  }while($i<=5)
?>
Output

Number 1

Number 2

Number 3

Number 4

Number 5
===========================

For loop

In For loop then statement will be excuted till the condition is fullfill.

===========================
for (initilization; condition; increment)
{
  code here...;
}

===========================
Exercise 1:

<?php

for ($i=1; $i<=5; $i++)

  {

  echo "Number".$i;

  }

?>
Output

Number 1
Number 2
Number 3
Number 4
Number 5

Related Posts:

  • PHP Loop Loop execute some statement many times till the condition is fullfill. There are three type or loops. these loops do same work execute statement man… Read More
  • What is PHP? What is PHP?PHP is basically use for web developing dynamic website.Example of dynamic website are facebook.com,google.com etc.About Web DevelopmentW… Read More
  • Array in PHP Suppose we want to store 100 data item. So we need 100 different variable. So this is very typical work for programmer to manage 100 different variab… Read More
  • HTML Form tag When creating textbox. labels,textarea , radio button etc. So this necessary to send these control value to the server.code:<form name="formanme" … Read More
  • If else statement in php if statement is use to check condition if condition is true then body of your code will be  execute.Syntaxif (condition){Code body}Exercise 1:&l… Read More

0 (mga) komento:

Post a Comment

Get updates

Twitter Facebook Google Plus LinkedIn RSS Feed Email

Get Free Updates in Your Email


Enter your email address:

Popular Posts

A visitor from Ashburn viewed 'PinoySourceCode' 21 hrs 20 mins ago
A visitor from Bengaluru viewed 'PinoySourceCode' 22 hrs 6 mins ago
A visitor from Iriga viewed 'PinoySourceCode' 2 days 15 hrs ago
A visitor from Ashburn viewed 'PinoySourceCode' 2 days 21 hrs ago
A visitor from Nairobi viewed 'PinoySourceCode' 3 days 7 hrs ago
A visitor from Laval viewed 'PinoySourceCode' 3 days 12 hrs ago
A visitor from Kigali viewed 'PinoySourceCode' 3 days 12 hrs ago
A visitor from St petersburg viewed 'PinoySourceCode' 4 days 1 hr ago
A visitor from Hamadan viewed 'PinoySourceCode' 4 days 1 hr ago
A visitor from California viewed 'PinoySourceCode' 4 days 1 hr ago