Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2018-02-24 05:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (310 votes). Check out past polls.

    Notices?