Re: [PHP-LANG] Duff's device

[email protected] (Peter Bowen)
Newsgroups php.lang
Message-ID <[email protected]>
I'm not suprised that it doesn't work. I've seen this before, but never quite understood how the compiler handles the do..while loop.  Logically, I understand how it works, but I'm not sure how the program finds the beginnning of the loop.

Thanks.
Peter

> 
> Just wondering:
> 
> as PHP syntax is heavily based on C syntax i was curious if it 
> would accept this code snippet:
> 
> 
> 
>   <?php
> 
>   $to="";
>   $from="abcdefghijklmnopqrstuvwxyz";
>   $count=12;
> 
>   $n = ($count + 7) / 8;      
>   $i=0;
>      switch ($count % 8)
>      {
>      case 0:        do {  $to .= $from{$i++};
>      case 7:              $to .= $from{$i++};
>      case 6:              $to .= $from{$i++};
>      case 5:              $to .= $from{$i++};
>      case 4:              $to .= $from{$i++};
>      case 3:              $to .= $from{$i++};
>      case 2:              $to .= $from{$i++};
>      case 1:              $to .= $from{$i++};
>                         } while (--$n > 0);
>      }
> 
>   echo $to;
> 
>   ?>
> 
> 
> 
> sure enugh it didn't although the C equvalent is indead legal
> 
> -> http://www.tuxedo.org/~esr/jargon/html/entry/Duff's-device.html
> 
>   ;)
> 
> -- 
> Hartmut Holzgraefe  [email protected]  http://www.six.de  +49-711-99091-77
> 
> -- 
> PHP Language Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> To contact the list administrators, e-mail: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.