iLTC Home
Bookmark iLTC!
iLTC Google Boards

Google Groups
Receive The Code in Email!



Categories

Perl
  • Perl Tutorials Beginners

    Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

    HTML
  • HTML Tutorials



  • Perl with cheese...
    123,745

    iLoveTheCode.com
    Perl > Perl Tutorials How To Easy > Exit a Loop with Last

    Exit a Loop with Last



    To exit a loop when a condition is met type:

    last;


    Example:

    @dr=("London", "Paris", "Tokyo");

    foreach $dr(@dr) {

    if ($dr eq "Paris") {
    print "Our city: $dr<br>";
    last;
    }
    else {
    print "Not our city: $dr<br>";
    }
    }


    Which prints:
    Not our city: London
    Our city: Paris


    -The array @dr contains our cities.
    -We loop over the array with foreach.
    -We say "If $dr equal Paris, print and exit the loop."

    The first time through the loop "else" is executed and London gets printed. The second time through the loop, the "if" condition is met, so we print and exit. The third time through the loop never happens.



    Copy and Paste Perl Code:

    #!/usr/bin/perl

    print "Content-type:text/html\n\n";


    @dr=("London", "Paris", "Tokyo");

    foreach $dr(@dr) {

    if ($dr eq "Paris") {

    print "Our city: $dr<br>";
    last;

    }
    else {
    print "Not our city: $dr<br>";
    }
    }

    exit;



    Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
    Previous Article: Opening and Reading a Directory in Perl
    Next Article: Putting Two Strings Together, Concatenate





    CSSCSS

    Eric Meyer

    New $29.69

    Dreamweaver CS3Dreamweaver CS3

    David McFarland

    New $29.69

    Bulletproof Web DesignBulletproof Web Design

    Dan Cederholm

    New $23.99

    jQuery in ActionjQuery in Action

    Bear Bibeault, Yeh...

    New $26.39

    HTML & XHTMLHTML & XHTML

    Chuck Musciano, Bi...

    New $29.99

    Head First HTML with CSS...Head First HTML with CSS & XHTML

    Eric Freeman, Elis...

    New $23.99

    JavaScriptJavaScript

    David Flanagan

    New $31.49

    New Perspectives on HTML...New Perspectives on HTML and XHTML 5...

    Partrick Carey

    New $67.45

    CSS MasteryCSS Mastery

    Andy Budd, Simon C...

    New $23.85


    Of Interest:
  • Finding the Length (Index Numbers) of an Array in Perl
  • Redirect to a Different URL in Perl
  • Getting Server Time in Perl
  • Renaming a File with Perl's RENAME Function
  • Call your Function in Javascript
  • Setting a Cookie using Javascript
  • Get Query String Using Javascript
  • Use OnMouseOver in Javascript
  • HTML Subscript Text
  • HTML Superscript Text
  • HTML Codes
  • HTML Color Chart

  • More Articles:
  • Redirect to a Different URL in Perl
  • Create a Subroutine in Perl
  • To Sort an Array in Perl
  • Delete a File Using unlink in Perl
  • onClick Javascript
  • Close Window with window.close in Javascript
  • Formatting Time in Javascript
  • Use onLoad to Call More than One Function with Javascript
  • Create a Function in Javascript
  • Make a Line Return Using HTML
  • HTML Space
  • HTML Subscript Text
  • HTML Body Tag

  • Search iLTC w/ Google





    Recent Articles

  • Javascript Focus Form Field
  • Javascript Lowercase Text
  • Javascript Uppercase Text
  • Javascript Superscript Text
  • Javascript Subscript Text
  • Make Text Blink Using Javascript
  • Make a String into a Link in Javascript
  • Javascript Italics Text
  • Javascript Bold Text
  • Javascript Redirect
  • HTML Frames
  • HTML Color Chart
  • HTML Link
  • Javascript Status Bar








  • Perl Programming - Javascript Programming - Maybe Some PHP - Free Scripts - ILoveTheCode
    All Content © 2006 iLoveTheCode.com


    Contact Chris | About this Site


    420,506
    Counter by iLoveTheCode.com


    Last Modified: Friday, 23-Jun-2006 07:23:13 EDT