PHP while / do..while / for loop / foreach

In programming, it is often essential to replicate the same block of code a given number of times, or until a definite state is met. This can be accomplished by using looping statements. PHP supports four major looping statements:

PHP have four looping types.

while – loop through a block of code if & as long as particular condition is true
do..while – loop through a block of code once, & then repeats the loop as long as the particular condition is true
for loop – loop through a block of code a specified number of times
foreach – loop through a block of code for each element in an array


While Loop Syntax

while(condition is true)
{
code to be executed;
}


Do While Loop Syntax

do
{
code to be executed;
}
while(condition is true);


For Loop Syntax

for(initialization; condition; increment)
{
code to be executed;
}


foreach Loop Syntax

foreach($array as $value)
{
code to be executed;
}




Coding Tag

Coding Tag always happy to serve you in Information Technology (IT). Learn HTML, CSS, Javascript, PHP, Android, Digital Marketing, Latest IT News and many more.

Leave a Reply

avatar
  Subscribe  
Notify of