Examveda
Examveda

What will be the output of the following PHP code ?
<?php
$i = "";
while ($i)
{   
    print "hi";
} 
while($i < 8)
    $i++;
print "hello";
?>

A. Hi is printed 8 times, hello 7 times and then hi 2 times

B. Hi is printed 10 times, hello 7 times

C. Hi is printed once, hello 7 times

D. Hi is printed once, hello 7 times and then hi 2 times

Answer: Option D

Solution(By Examveda Team)

The while loop ends only when a } is encountered.

This Question Belongs to PHP >> Control Structures(Loop In PHP)

Join The Discussion

Related Questions on Control Structures(Loop in PHP)