Advertisements
Advertisements
प्रश्न
Explain Looping Structure in PHP.
टीपा लिहा
Advertisements
उत्तर
- Looping Structures are useful for writing iteration logics.
- It is the most important feature of many programming languages, including PHP.
- They are implemented using the following categories:
- For Loop
- For each Loop
- while Loop
- Do while Loop
- For Loop:
For loop is an important functional looping system which is used for iteration logics when the programmer know in advance how many times the loop should run.
Syntax:for (init counter; test counter; increment counter) { code to be executed; } - Foreach Loop:
foreach loop is exclusively available in PHP. It works only with arrays. The loop iteration deepens on each KEY Value pair in the Array. For each, loop iteration the value of the current array element is assigned to $value variable and the array pointer is shifted by one, until it reaches the end of the array element.
Syntax:for each ($array as $value) { code to be executed; } - While Loop:
While loop is an important feature which is used for simple iteration logics. It is checking the condition whether true or false. It executes the loop if a specified condition is true.
Syntax:while (condition is true) { code to be executed; } - Do While Loop:
Do while loop always run the statement inside of the loop block at the first time execution. Then it is checking the condition whether true or false. It executes the loop, if the specified condition is true.
Syntax:do { code to be executed; } while (condition is true);
shaalaa.com
Looping Structure
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
APPEARS IN
संबंधित प्रश्न
What will be displayed in a browser when the following PHP code is executed:
<?php
for (Scounter = 20; $counter< 10;
$counter++)
{
echo “Welcome to Tamilnadu “;
}
echo “Counter is: Scounter”;
?>PHP supports which types of looping techniques ______.
What will be the output of the following PHP code?
<?php
for ($x = -1; $x < 10;--$x)
{
print $x;
}
?>Define for loop in PHP.
Write Syntax of For loop in PHP.
Write Syntax of while loop in PHP.
Write the features Looping Structure.
Discuss in detail about Foreach loop.
Explain the process Do while loop.
Explain working of loops in array.
