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?
- While Loop.
- Do while Loop
- 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:-
echo "this is while condition: $am <br />";
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.
$ami = 3;
echo "this is Laravel Amit: $ami <br />";
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:-
for($num=1; $num<=5; $num++)
echo "this is for loop: $num <br />";