0

Can anyone teach me how to print "Hello World" 100 times without using the loop such as do, for, while, and foreach.
Thanks...

7
Contributors
8
Replies
12
Views
5 Years
Discussion Span
Last Post by blocblue
1
<?php

    function printvalue($val)
    {
         if($val>1)
               printvalue($val-1);
          echo $val."<br>";
         return;
    }

    printvalue(100);
?>

Edited by urtrivedi: -

0

as far as i know you have to loop, thats exactly what repeating something is.

urtrivedi has done a good example of recursion, its basically long hand of doing what while($i > 1) does.

If you don't want a loop type it out 100 times

4

How about something simple like:

echo str_repeat('Hello World ', 100);

R.

Votes + Comments
Indeed, like Python print 100*'Hello World ', only I do not know PHP deeply enough to suggest.
Simple but effective. Nice.
0

You can also do it this way...C++ style... The $z is rolling in its own grease a 100 times ..

  <?php
  call_user_func( $x = function( $yx, $z =1 ) {
echo (string)("Hello World <br/>"), $yx[floor($z/100)]($yx, ++$z);
}, array( $x, function(){} ));

?>

Edited by veedeoo: more info added

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.