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,703

    iLoveTheCode.com
    Perl > Perl Tutorials How To Easy > Write a WHILE LOOP in Perl, Carefully

    Write a WHILE LOOP in Perl, Carefully



    CAUTION: Be careful with WHILE because it is quite easy to cause an endless loop (which is bad). If you don't have access to killing the script, you can crash your browser and the server machine.

    Having said that, you create and name a variable $hu

    $hu=0;

    while ($hu < 10) {
    print "$hu, ";
    $hu++;
    }

    Which prints:
    0, 1, 2, 3, 4, 5, 6, 7, 8, 9,

    In plain English:

    The first time through the WHILE LOOP, $hu equals 0.

    $hu is incremented by one each time with $hu++ which means $hu plus one.

    When $hu reaches 10, the loop is exited because $hu is no longer less than 10.

    If you forgot the $hu++, this script would endlessly loop, because $hu would always be zero. This would be bad and would crash your browser and probably the server. SO BE CAREFUL WITH THE "WHILE LOOP"!

    Copy and Paste Perl Code:

    #!/usr/bin/perl

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

    $hu=0;

    while ($hu < 10) {
    print "$hu, ";
    $hu++;
    }

    exit;


    While Loop Perl CGI - See in Action (new window)


    Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
    Previous Article: Write a FOR LOOP in Perl
    Next Article: INCREMENT and DECREMENT a Variable in Perl





    Bulletproof Web DesignBulletproof Web Design

    Dan Cederholm

    New $23.99

    CSSCSS

    Eric Meyer

    New $29.69

    CSS MasteryCSS Mastery

    Andy Budd, Simon C...

    New $23.85

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

    Eric Freeman, Elis...

    New $23.99

    jQuery in ActionjQuery in Action

    Bear Bibeault, Yeh...

    New $26.39

    Creating Web SitesCreating Web Sites

    Matthew MacDonald

    New $19.77

    HTML & XHTMLHTML & XHTML

    Chuck Musciano, Bi...

    New $29.99

    Dreamweaver CS3Dreamweaver CS3

    David McFarland

    New $29.69

    HTML, XHTML, and CSS, Si...HTML, XHTML, and CSS, Sixth Edition ...

    Elizabeth Castro

    New $23.09


    Of Interest:
  • Renaming a File with Perl's RENAME Function
  • Exit a Loop with Last
  • To See if a Directory Exists in Perl
  • Getting Server Time in Perl
  • Increment a Variable in Javascript
  • Match with a Regular Expression, REGEX, in Javascript
  • Annoy Users with onBlur in Javascript
  • Change a Form Field with Javascript
  • HTML Tables
  • Make Strikethrough Text Using HTML
  • HTML Subscript Text
  • HTML Font Code

  • More Articles:
  • Add to End of an Array with Push in Perl
  • Undefine an Array in Perl
  • Substitute in Perl
  • Combine, Put Two Arrays Together in Perl
  • onClick Javascript
  • Opening an Alert Box in Javascript
  • Formatting Time in Javascript
  • Create a Function in Javascript
  • Environmental Variables Available in Javascript using Navigator Object
  • HTML Subscript Text
  • HTML Superscript Text
  • HTML Underline Text
  • HTML Title 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,464
    Counter by iLoveTheCode.com


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