Define What is Loop and what are the Types with Syntax.

In this tutorial i’m going to define what is loop and what are the types with syntax.

What is Loop?

Any Repeated task more than one time that is called Loop. In a loop structure, the loop asks a question. If the answer requires action, it is executed. Using loops in computer programs simplifies rather optimizes the process of coding.

Types of Loops?

  1. Do while Loop
  2. For Loop

While Loop:- While loop is a pre-test loop. It first test a specified conditional expression and as long as the condition true action taken. While loop also known as Entry Control Loop

Syntax with example:-

<?php

$am =1;

while($am<=6;
{
echo "this is while condition: $am <br />";
$am++;
}
?>

OutPut 👇

2. Do while Loop:- Do while loop is similar to while loop but the condition is checked after the loop. This ensure that the loop body is run at least once.

<?php

$ami = 3;

do{
echo "this is Laravel Amit: $ami <br />";
$ami++;

}while($ami<=6);

?>

OutPut 👇

3. For Loop :- The for is frequently used usullay where the loop will be traversed a fixed numbers of times. A loop variable is used to control the loop

Syntax + example:-

<?php

for($num=1; $num<=5; $num++)
{
echo "this is for loop: $num <br />";
}

?>

OutPut 👇

Thanks …

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Amit Kumar

Hi I am Amit Experienced Web Developer with a demonstrated history of working in the information technology and services industry.