Advertisements
Advertisements
प्रश्न
Differentiate For each and While loop.
थोडक्यात उत्तर
Advertisements
उत्तर
| 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
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
APPEARS IN
संबंधित प्रश्न
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”;
}
?>Consider the following code
<? php
$count=12;
do{
printf(“%d squared=%d<br/>”,
$count, pow($count,2));
} while($count<4);
?>
What will be the output of the code.
What will be the output of the following PHP code?
<?php
for ($x = 1; $x < 10;++$x)
{
print “*\t”;
}
?>Define Looping Structure in PHP.
Write Syntax of For loop in PHP.
Write Syntax of For each loop in PHP.
Write short notes on Do while Loop.
Discuss in detail about Foreach loop.
Explain concepts of for loop with example.
Explain working of loops in array.
