ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

PHP Looping Statements Aptitude Questions and Answers

PHP Looping Statements Aptitude: This section contains aptitude questions and answers on Looping Statements.
Submitted by Nidhi, on March 10, 2021

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

ADVERTISEMENT
ADVERTISEMENT




Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.