Tags
Asked 3 years ago
13 Jul 2021
Views 147
Maybelle

Maybelle posted

What are the 3 types of loops ?

What are the 3 types of loops ?
iptracker

iptracker
answered Oct 9 '21 00:00

PHP has the following loop .
1. for loop

for loop example :

for($i=0;$i<10;$i++){
echo $i;
}


2. for each loop

foreach example :

$array=array("a",'b',"c");
for($array as $val){
echo $val;
}


3. while loop

while(condition check){
 //do something
}


4. do .. while loop

$i = 0;
do {
    echo $i;
} while ($i > 0);


5. goto statement

$i=0;
b:

$i++;
if($i==10){
	goto c;
}
echo $i;
goto b;
c:

it will print 123456789
Post Answer