Advertisements
Advertisements
Question
Explain concepts of for loop with example.
Advertisements
Solution
For loop is an important functional looping system which is used for iteration logic when the programmer knows in advance how many times the loop should run.

Flowchart of For loop Structure and Flow chart
Syntax-
for (init counter; test counter; increment counter)
{
code to be executed;
>
Example:
<?php
for ($i = 0; $i<= 10; $i++)
{
echo “The number is: $i<br>”;
}
?>APPEARS IN
RELATED QUESTIONS
for ($ x=0; $ x<5; x++)
echo “Hai”
The above loop executes how many no of times?
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”;
}
?>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 “*\t”;
}
?>What will be the output of the following PHP code?
<?php
for ($x = -1; $x < 10;--$x)
{
print $x;
}
?>What is For each loop in PHP?
Write Syntax of For loop in PHP.
Write Syntax of while loop in PHP.
Write short notes on Do while Loop.
