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 with examples.

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. While Loop.
  2. Do while Loop
  3. 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 ā€¦

Tagged : / / / /