PHP While Loops


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











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    The loop never ends as m is always incremented and then decremented.


  1. What will be the output of the following PHP code ?
    <?php
    $p = 5;
    while($p = 20)
    {
    print "INDIA";
    }
    print "USA";
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    While condition always gives 1.



  1. What will be the output of the following PHP code ?
    <?php
    $s = "";
    while ($s = 20)
    {
    print "Interveiw";
    }
    print "Mania";
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    While condition always gives 1.


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











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    p is decremented in the first while execution and then continuously incremented back.



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











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    As it is && operator it is being incremented and decremented continuously.