MCQs Test!! VB Basic Test !! Essentials of VB !! Creating User Services !! function !! Anatomy !! GK March-2019 !! DATA TYPES IN JAVA !! Classes ,Constructor ,Methods,Inheritance !! Ecology-I !! Biology 2019 !! Gk april 2019 !! Biology (living world) !! Plant anatomy !! CELL STRUCTURES AND FUNCTION !! General biology !! Human physiology !! Data structure !! Ecology-II !! GK TEST !! Reproduction in plants !! Human reproduction !! The ABC of C !! Operating system set1 !! Operating system set2 !! Gk and current affairs !! Animal kingdom !! Number system !! Animal kingdom-II !! Gk TEST-III !! Number series !! Microorganisms !! Interview question in c !! Time and Work !! Percentage !! General history !! Average !! Cells !! Locomotion and Movement !! paging !! Bacteriology !! Page replacement policy !! Secondary memory and Disk scheduling !! Introduction of Nervous System and neurons !! Plant harmones !! Transport and Mineral Nutrition in Plants !! Neurotransmitters !! Modern Indian History !! Photosynthesis in Plants !! Modern Indian History-II !! Plant respiration !! Environment & Biodiversity !! Environment & Biodiversity - II !! Algae, Bryophytes, Pteridophytes !! Area !! Cricket !! Days of the Year (India and the World) !! Plant Pathology - I !! Indian Transport System !! Plant Pathology - II !! Aptitude !! Biology !! Botany !! C language !! Computer Science !! Core Java !! Gate !! GK !! Mysql !! Operating system !! Physics !! VB-Visual Basic !! Zoology

PHP Programing language

Loops in PHP
Previous Home Next

Looping Statement

If some task is used in the script repeatedly in php there is a need of Looping Statement until a certain condition met.

Types of Looping Statement:

The following Looping Statements support by PHP

  1. while Statement
  2. do....while Statement
  3. for Statement
  4. foreach Statement
while Statement

while Loop statement runs the same block of code repeatedly until a condition met.

Syntax:

 

while(condition)
{
 block of code to be executed;
}

Example:

<html>
<head>
<title>while Loop in PHP</title>
</head>
<body>

<?php
$A=0;
while($A<=15)
{
echo "$A<br/>";
$A++;
}
?>

</body>
</html>

Output:

do....while Statement

do....while Statement is works as while loop. It runs the block of code atleast once after that runs depending upon the condition.

Syntax:

Example:

<html>
<head>
<title>do....while Loop in PHP</title>
</head>
<body>

<?php
$A=0;
do
{
echo "$A<br/>";
$A++;
}while($A<15)
?>

</body>
</html>

Output:

for Statement

for statement is used when you know how many times you want to execute a statement or a block of statements. And everything is defined in single line.

Syntax:
for(initialization; condition; increment/decrement)
{
block of code to be executed;
}

Example:

<html>
<head>
<title>for Loop in PHP</title>
</head>
<body>

<?php
$total = 0;
for ( $x = 1; $x <= 10; $x++) 
{ 
$total = $total + $x;
}
echo "The total sum: ".$total."<br />";
?>

</body>
</html>

Output:

foreach Statement

foreach loop works on arrays, and is used to loop through each key/value pair in an array.

Syntax:
foreach(array as value)
{
block of code to be executed;
}

Example

<html>
<head>
<title>foreach Loop in PHP</title>
</head>
<body>

<?php 
$dress = array("sarees", "lehengas", "gowns", "skirts"); 

foreach ($dress as $value) 
{
echo "$value <br>";
}
?> 
</body>
</html>

Output:

Previous Home Next