0% found this document useful (0 votes)
2 views

php2

Uploaded by

hamdihazmi398
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

php2

Uploaded by

hamdihazmi398
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Chapter 5 PHP : Conditional and looping statements

1. Conditional statements
1.1. if statement
a.
if (condition)
{instruction;}
b.
if (condition)
{ instructions1; }
else
{instructions2;}
c.
if (condition1)
{ instructions1; }
else if (condition2)
{ instructions2 ;}

1.2. switch statement

switch ( expression )
{
case value1 : { instructions1 ; break ;}
case value2 : { instructions2 ; break ;}
….
default : { instructionsN ;}
}

2. Looping statements
2.1. while statement
while (condition)
{
instructions;
}

2.2. do… while sratement

do
{
instructions;
} while (condition) ;

Mohamed Hedi Elhajjej Page 1


Example:

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

12345

2.3. for statement

for (initialization; condition ; increment or decrement instruction )


{
Instructions…
}

Example

<?php

for($i=0;$i<50;$i++)
{
echo $i.'<br>';
}
?>

Mohamed Hedi Elhajjej Page 2

You might also like