PHP Tutorial

PHP Examples

PHP Practice

PHP Looping Statements Aptitude Questions and Answers

PHP Looping Statements Aptitude: This section contains aptitude questions and answers on Looping Statements. By Nidhi Last updated : December 15, 2023

This section contains Aptitude Questions and Answers on PHP Looping Statements.

1) There are the following statements that are given below, which of them are correct about looping statements?
  1. The looping statements are used to execute one or more statements multiple times.
  2. The looping statements also known as iterative statements.
  3. The looping statements also known as decision-making statements.
  4. The looping statements can be used within the class only.

Options:

  1. A and B
  2. A and C
  3. A, B, and D
  4. A, C, and D

2) Which of the following loops can be used in PHP?
  1. while
  2. do ... while
  3. for
  4. foreach

Options:

  1. A and B
  2. A, B, and C
  3. A and C
  4. A, B, C, and D

3) Which of the following loops are the entry control loop in PHP?
  1. while
  2. do ... while
  3. for
  4. None of the above

Options:

  1. A and B
  2. A and C
  3. A, B, and C
  4. A, B, C, and D

4) What is the correct output of the given code snippets in PHP?
<?php
$iLoop = 1;
while ($iLoop <= 5)
{
    echo $iLoop;
    iLoop++;
}
?>
  1. 12345
  2. 01234
  3. Error
  4. Infinite loop

5) What is the correct output of given code snippets in PHP?
<?php
$iLoop = 1;
while ($iLoop <= 5)
{
    echo $iLoop;
    iLoop;
}
?>
  1. 12345
  2. 01234
  3. Error
  4. Infinite loop

6) What is the correct output of given code snippets in PHP?
<?php
$iLoop = 1;
while ($iLoop <= 5) echo ++$iLoop;
?>
  1. 12345
  2. 01234
  3. 23456
  4. Error

7) What is the correct output of given code snippets in PHP?
<?php
$iLoop = 1;
while ($iLoop <= 5, $iLoop++)
{
    echo $iLoop;
}
?>
  1. 12345
  2. 01234
  3. 23456
  4. Error

8) What is the correct output of given code snippets in PHP?
<?php
$iLoop = 0;
while ($iLoop <= 5)
{
    $++iLoop;
    echo $iLoop * $iLoop . " ";
}
?>
  1. 1 4 9 16 25
  2. 0 1 4 9 16 25 36
  3. 0 1 4 9 16 25
  4. Error

9) What is the correct output of given code snippets in PHP?
<?php
$iLoop = 0;

++$iLoop;
while ($iLoop <= 5)
{
    $iLoop++;
    echo $iLoop * $iLoop . " ";
}
?>
  1. 1 4 9 16 25
  2. 4 9 16 25 36
  3. 4 9 16 25
  4. Error

10) What is the correct output of the given code snippets in PHP?
<?php
$iLoop = 10;

while ($iLoop <= 5)
{
    echo $iLoop . " ";
    $iLoop = $iLoop - 1;
}
?>
  1. 10 9 8 7 6 5
  2. 10 9 8 7 6
  3. Infinite loop
  4. None of the above

11) What is the correct output of the given code snippets in PHP?
<?php
$iLoop = 5;

dowhile($iLoop > 0)
{
    echo $iLoop . " ";
    $iLoop = $iLoop - 1;
}
?>
  1. 5 4 3 2 1 0
  2. 5 4 3 2 1
  3. Error
  4. None of the above

12) What is the correct output of the given code snippets in PHP?
<?php
$iLoop = 5;
do
{
    echo $iLoop . " ";
    $iLoop = $iLoop - 1;
}
while ($iLoop > 0)
?>
  1. 5 4 3 2 1 0
  2. 5 4 3 2 1
  3. Error
  4. None of the above

13) Is do… while loop executes at least once?
  1. Yes
  2. No

14) The do … while loop is exit control loop?
  1. Yes
  2. No

15) What is the correct output of the given code snippets in PHP?
<?php
$iLoop = 0;

while ($iLoop <= 5)
{
    echo $iLoop . " ";
    $iLoop = $iLoop + 1;

    if ($iLoop == 2) continue;
}
?>
  1. 0 1 3 4 5
  2. 0 1 2 3 4 5
  3. Error
  4. None of the above

16) What is the correct output of the given code snippets in PHP?
<?php
$iLoop = 0;

while ($iLoop <= 5)
{
    $iLoop = $iLoop + 1;
    if ($iLoop == 2) continue;
    echo $iLoop . " ";
}
?>
  1. 0 1 3 4 5
  2. 0 1 2 3 4 5
  3. 1 3 4 5 6
  4. Error

17) What is the correct output of the given code snippets in PHP?
<?php

for ($iLoop = 0;$iLoop < 5;$iLoop++)
{
    echo $iLoop . " ";
}
?>
  1. 0 1 2 3 4
  2. 0 1 2 3 4 5
  3. Error
  4. None of the above

18) What is the correct output of the given code snippets in PHP?
<?php

for ($iLoop = 0;true;$iLoop++)
{
    echo $iLoop . " ";
    if ($iLoop == 4) break;
}
?>
  1. 0 1 2 3 4
  2. 0 1 2 3 4 5
  3. Error
  4. None of the above

19) What is the correct output of the given code snippets in PHP?
<?php

for ($iLoop = 0;$iLoop < 5;)
{
    echo $iLoop . " ";
    $iLoop++;
}
?>
  1. 0 1 2 3 4
  2. 0 1 2 3 4 5
  3. Error
  4. None of the above

20) What is the correct output of the given code snippets in PHP?
<?php

$iLoop = 0;
for (;$iLoop;)
{
    echo $iLoop . " ";
    $iLoop++;

    if ($iLoop == 4) break;
}
?>
  1. 0 1 2 3 4
  2. 0 1 2 3
  3. Error
  4. None of the above

21) What is the correct output of the given code snippets in PHP?
<?php

$iLoop = 0;
for (;1;)
{
    echo $iLoop . " ";
    $iLoop++;

    if ($iLoop == 4) break;
}
?>
  1. 0 1 2 3
  2. 0 1 2 3 4
  3. Error
  4. None of the above

22) What is the correct output of the given code snippets?
<?php
$i = 0;

for ($i = 0;$i < 3;$i++)
{
    for ($j = 0;$j < 2;$j++) echo $i . " ";
}

?>
  1. 0 0 1 1 2 2
  2. Error
  3. Infinite loop
  4. None of the above

23) What is the correct output of the given code snippets?
<?php

$days = array(
    "sun",
    "mon",
    "tue"
);

foreach ($dayin $days)
{
    echo "$day ";
} ?>
  1. sun mon tue
  2. infinite lop
  3. Error
  4. None of the above

24) What is the correct output of the given code snippets in PHP?
<?php

$days = array(
    "sun",
    "mon",
    "tue"
);

foreach ($days as $day)
{
    echo "$day ";
} ?>
  1. sun mon tue
  2. infinite lop
  3. Error
  4. None of the above

25) What is the correct output of the given code snippets?
<?php

$days = array(
    "sun",
    "mon",
    "tue"
);

foreach ($days as $day)
{
    if ($day == "mon") echo "monday "
    else echo "$day ";
}
?>
  1. sun mon tue
  2. sun monday tue
  3. Error
  4. None of the above

Learn PHP programming with our PHP tutorial.

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.