Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

The Best Infinite Loop

by zdog (Priest)
on Oct 17, 2000 at 02:21 UTC ( #37048=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    #!/usr/bin/perl -w
    
    ...
        'for'   => sub { $_ = 0; for   (;;)  { $_++; last if ($_ == 1000);
    + } },
        'block' => sub { $_ = 0;             { $_++; redo if ($_ < 1000); 
    + } }
    });
    
  2. or download this
    Benchmark: timing 10000 iterations of block, for, while...
         block:  8 wallclock secs ( 8.13 usr +  0.00 sys =  8.13 CPU)
    ...
         block: 66 wallclock secs (65.01 usr +  0.00 sys = 65.01 CPU)
           for: 63 wallclock secs (63.18 usr +  0.00 sys = 63.18 CPU)
         while: 64 wallclock secs (64.20 usr +  0.00 sys = 64.20 CPU)  
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://37048]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2014-11-27 10:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (183 votes), past polls