PHP

PHP

While Loops has 19 Questions
What will be the output of the following PHP code ?
  1. <?php
  2. while()
  3. {
  4.     print "hi";
  5. }
  6. ?>

infinite loop
hi
no output
error
What will be the output of the following PHP code ?
  1. <?php
  2. do
  3. {
  4.     print "hi";
  5. }
  6. while(0);
  7. print "hello";
  8. ?>

infinite loop
hihello
hello
error
What will be the output of the following PHP code ?
  1. <?php
  2. $i = 0
  3. do
  4. {
  5.     print "hi";
  6.     $i++;
  7. }
  8. while ($i != 3);
  9. ?>

hi hi
hi
hi hi hi hi
no output
What will be the output of the following PHP code ?
  1. <?php
  2. $i = "";
  3. while ($i)
  4. {   
  5.     print "hi";
  6. } 
  7. while($i < 8)
  8.     $i++;
  9. print "hello";
  10. ?>

Hi is printed 8 times, hello 7 times and then hi 2 times
Hi is printed 10 times, hello 7 times
Hi is printed once, hello 7 times
Hi is printed once, hello 7 times and then hi 2 times
What will be the output of the following PHP code ?
  1. <?php
  2. $i = "";
  3. while($i)
  4. {   
  5.     print "hi";
  6. }
  7. print "hello";
  8. ?>

hello
infinite loop
hihello
error
What will be the output of the following PHP code ?
  1. <?php
  2. $i = 0
  3. do
  4. {
  5.     $i++;
  6. }
  7. while ($i < 3);
  8. print $i;
  9. ?>

2
3
0
1
What will be the output of the following PHP code ?
  1. <?php
  2. $i = 0
  3. while ($i < 3)
  4. {
  5.     $i++;
  6. }
  7. print $i;
  8. ?>

2
3
0
1
What will be the output of the following PHP code ?
  1. <?php
  2. $i = 0
  3. while ($i < 3)
  4. {
  5.     print "hi";
  6.     $i--;
  7. }
  8. print "hello"
  9. ?>

hi hi hello
hi hi hi hello
hi hi hi hi hello
infinite loop
What will be the output of the following PHP code ?
  1. <?php
  2. $i = 0
  3. while ($i != 3)
  4. {
  5.     print "hi";
  6. 	$i++;
  7. }
  8. ?>

hi hi
hi hi hi
hi hi hi hi
no output
What will be the output of the following PHP code ?
  1. <?php
  2. do
  3. {
  4.     print "hi";
  5. }
  6. while(0);
  7. print "hello";
  8. ?>

infinite loop
hihello
hello
error
What will be the output of the following PHP code ?
  1. <?php
  2. $i = 0;
  3. while($i = 10)
  4. {   
  5.     print "hi";
  6. }
  7. print "hello";
  8. ?>

hello
infinite loop
hihello
error
What will be the output of the following PHP code ?
  1. <?php
  2. $i = "";
  3. while ($i = 10)
  4. {   
  5.     print "hi";
  6. }
  7. print "hello";
  8. ?>

hello
infinite loop
hihello
error
What will be the output of the following PHP code ?
  1. <?php
  2. $i = 5;
  3. while (--$i > 0)
  4. {   
  5.     $i++; print $i; print "hello";
  6. }
  7. ?>

4hello4hello4hello4hello4hello.....infinite
5hello5hello5hello5hello5hello.....infinite
no output
error
What will be the output of the following PHP code ?
  1. <?php
  2. $i = 5;
  3. while (--$i > 0 && ++$i)
  4. {   
  5.     print $i;
  6. }
  7. ?>

5
555555555...infinitely
54321
error
What will be the output of the following PHP code ?
  1. <?php
  2. $i = 5;
  3. while (--$i > 0 || ++$i)
  4. {   
  5.     print $i;
  6. }
  7. ?>

54321111111....infinitely
555555555...infinitely
54321
5
What will be the output of the following PHP code ?
  1. <?php
  2. $i = 0;
  3. while(++$i || --$i)
  4. {   
  5.     print $i;
  6. }
  7. ?>

1234567891011121314....infinitely
01234567891011121314...infinitely
1
0
What will be the output of the following PHP code ?
  1. <?php
  2. $i = 0;
  3. while (++$i && --$i)
  4. {   
  5.     print $i;
  6. }
  7. ?>

1234567891011121314....infinitely
01234567891011121314...infinitely
no output
error
What will be the output of the following PHP code ?
  1. <?php
  2. $i = 2;
  3. while (++$i)
  4. {   
  5.     while ($i --> 0)
  6.         print $i;
  7. }
  8. ?>

210
10
no output
infinite loop
What will be the output of the following PHP code ?
  1. <?php
  2. $i = 2;
  3. while (++$i)
  4. {   
  5.     while (--$i > 0)
  6.         print $i;
  7. }
  8. ?>

210
10
no output
infinite loop