Advertisements
Advertisements
Question
Differentiate For each and While loop.
Answer in Brief
Advertisements
Solution
| While loop | Foreach loop | |
| Working principle | The while statement will execute a block of code If and as Song as a test expression, is true. | The foreach statement is used to loop through arrays. |
| Working principle | If the test expression is true then the code block will be executed. After the code has executed the test expression will again be evaluated and the loop will continue until the test expression is found to be false. | For each pass, the value of the current array element is assigned to $value and the array pointer is moved by one and in the next pass, the next element will be processed. |
| Syntax |
|
|
shaalaa.com
Looping Structure
Is there an error in this question or solution?
APPEARS IN
RELATED QUESTIONS
The loop exclusively used for arrays is _____.
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”;
?>What will be displayed in a browser when the following PHP code is executed;
<?php
for ($counter = 10; $counter < 10;
$counter = $counter + 5){
echo “Hello”;
}
?>List out Looping Structure in PHP.
Write Syntax of while loop in PHP.
Write Syntax of Do while loop in PHP.
Explain the use of for each loop in PHP.
Write the features Looping Structure.
Explain the process Do while loop.
Explain working of loops in array.
