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:

  • 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
  • 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
  • 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
  • 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

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 Abuja viewed 'PinoySourceCode' 10 hrs 47 mins ago
A visitor from Charleston viewed 'Payroll system simple but functional using php ~ P' 11 hrs 31 mins ago
A visitor from Dire dawa viewed 'PinoySourceCode' 2 days 8 hrs ago
A visitor from Chandigarh viewed 'PinoySourceCode' 2 days 12 hrs ago
A visitor from Abuja viewed 'PinoySourceCode' 4 days 7 hrs ago
A visitor from Accra viewed 'PinoySourceCode' 4 days 20 hrs ago
A visitor from Hyderabad viewed 'Payroll system simple but functional using php ~ P' 9 days 7 hrs ago
A visitor from Fianarantsoa viewed 'PinoySourceCode' 9 days 9 hrs ago
A visitor from Kathmandu viewed 'PinoySourceCode' 9 days 16 hrs ago
A visitor from Riviere du rempart viewed 'PinoySourceCode' 9 days 19 hrs ago