PHP While Loops


  1. What will be the output of the following PHP code ?
    <?php
    $p = 0;
    while ($p++)
    {
    print $p;
    }
    print $p;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    As it is a post increment, it checks and then does not enter the loop, thus prints only 1.


  1. What will be the output of the following PHP code ?
    <?php
    $k = 10;
    while ($k < 30)
    {
    $k++;
    }
    print $k;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    The increment happens and then the check happens.



  1. What will be the output of the following PHP code ?
    <?php
    $t = 20;
    do
    {
    $t++;
    }
    while ($t < 60);
    print $t;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    The increment happens and then the check happens.


  1. What will be the output of the following PHP code ?
    <?php
    $num = 2;
    while ($num < 5)
    {
    print "Interview";
    $num--;
    }
    print "Mania";
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    There is no increment of num making it infinite.



  1. What will be the output of the following PHP code ?
    <?php
    $n = "";
    while($n)
    {
    print "Manjesh";
    }
    print "Ojha";
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    While accept does not accept anything other than a 0 or any other number as false and true.