Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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 having an uproarious good time at the Monastery: (3)
As of 2015-05-07 04:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    In my home, the TV remote control is ...









    Results (154 votes), past polls