Perl
  Home arrow Perl arrow Page 3 - Perl 101 (Part 3) - Looping The Loop
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PERL

Perl 101 (Part 3) - Looping The Loop
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2000-06-15

    Table of Contents:
  • Perl 101 (Part 3) - Looping The Loop
  • While You Were Sleeping...
  • ...Or Until You Wake Up
  • Dos And Don'ts
  • For Pete's Sake!
  • Every Comedian Needs An Exit
  • Grade School
  • Playing With Friends
  • So Many Choices...

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Perl 101 (Part 3) - Looping The Loop - ...Or Until You Wake Up


    (Page 3 of 9 )

    The not-so-distant cousin of Perl's "while" loop is its "until" loop, whichlooks like this:

    until (condition) { do this! }
    To illustrate the relationship between the "while" and "until" loops, readthese two sentences:

    WHILE you're less than twenty-one years of age, you can't drink!

    UNTIL you're over twenty-one years of age, you can't drink!

    In other words, the conditional expression to be evaluated in a "while"loop will be exactly the opposite of the one to be evaluated in an "until"loop. So take another look at the WEEP, which we've rewritten using an"until" statement:

    #!/usr/bin/perl # weighted employee evaluation program # call me WEEP! # ask the question print ("Are you satisfied with your salary? [y/n] "); # get an answer $reply = <STDIN>; chomp($reply); # keep asking until you get the reply you want until($reply eq 'y') { print ("Are you satisfied with your salary? [y/n] "); $reply = <STDIN>; chomp($reply); } print ("Employee satisfaction has always been this company's goal.\n"); print ("Thank you for making this experience an enriching one!\n");
    If you compare the "while" and "until" lines in the WEEP examples above,you'll see that the two conditional expressions are exactly the opposite ofeach other. And if you can't decide which one to use, try this little trick- translate your "until" or "while" statement into English, roll it aroundyour tongue, and see if it sounds right to you...

    This article copyright Melonfire 2000. All rights reserved.

    More Perl Articles
    More By Vikram Vaswani and Harish Kamath, (c) Melonfire


     

       

    PERL ARTICLES

    - More Templating Tools for Perl
    - Site Layout with Perl Templating Tools
    - Build a Perl RSS Aggregator with Templating ...
    - Looping, Security, and Templating Tools
    - Perl: Bon Voyage Lists and Hashes
    - Templating Tools
    - Perl: Number Crunching
    - Perl Debuggers in Detail
    - Debugging Perl
    - Perl: More on Lists and Hashes
    - Perl: Dimensional Lists
    - Perl: A Continuing Look at Hashes and Multid...
    - Perl: Another Round with Hashes
    - Perl Hashes
    - Perl Lists: A Final Look at List::Util





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway