iLTC Home
Bookmark iLTC!
iLTC Google Boards

Categories

Perl
  • Perl Tutorials Beginners

    Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

    HTML
  • HTML Tutorials



  • iLoveTheCode.com
    Javascript > Javascript Tutorials How To Easy > Write a For Loop in Javascript

    Write a For Loop in Javascript



    To write a for loop in Javascript:

    for(j=0;j<50;j++) {
    document.write(j + " ");
    }

    Which Prints:
    0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49


    -We created a variable and named it j because j is easy to type.
    -We started j at zero. j=0
    -We said as long as j is less than 50, keep going. j<50
    -We incremented, or added one, each time through the loop. j++
    -We used document.write to print j, plus a space, to the browser each time through the loop.


    Free Copy and Paste Javascript Code:

    <script type="text/javascript">
    <!--

    for(j=0;j<50;j++) {
    document.write(j + " ");
    }

    -->
    </script>


    Resources:
    Exit a For Loop in Javascript with Break



    Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
    Previous Article: Exit a For Loop in Javascript with Break
    Next Article: Increment a Variable in Javascript





    Struts 2 in ActionStruts 2 in Action

    Don Brown, Chad Da...

    New $29.69

    Head First AjaxHead First Ajax

    Rebecca Riordan

    New $29.69

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

    Eric Freeman, Elis...

    New $26.39

    HTML, XHTML, and CSS All...HTML, XHTML, and CSS All-in-One Desk...

    Andy Harris, Chris...

    New $23.09

    CSS MasteryCSS Mastery

    Andy Budd, Simon C...

    New $23.09

    CSSCSS

    Eric Meyer

    New $29.69

    Beginning Joomla!Beginning Joomla!

    Dan Rahmel

    New $29.69

    Learning Web DesignLearning Web Design

    Jennifer Niederst ...

    New $29.69


    Of Interest:
  • Matching with a Regular Expression, REGEX, in Perl
  • Finding the Length (Index Numbers) of an Array in Perl
  • Use chmod in Perl
  • To See if a Directory Exists in Perl
  • Exit a For Loop in Javascript with Break
  • Select All or Highlight Text Fields and Textareas Using Javascript
  • Get Query String Using Javascript
  • Call your Function in Javascript
  • HTML Tags
  • HTML Font Code
  • HTML Color Codes
  • HTML Body Tag

  • More Articles:
  • Encryption with the Crypt Function in Perl
  • Putting Two Strings Together, Concatenate
  • Write a WHILE LOOP in Perl, Carefully
  • Passing a Variable or Value to a Subroutine in Perl
  • onClick Javascript
  • PRINT to Browser with document.write Command in Javascript
  • Setting a Cookie using Javascript
  • Substitute in Javascript Using replace Method
  • Get Query String Using Javascript
  • HTML Codes
  • HTML Center
  • Make Italic Text Using HTML
  • HTML Space

  • 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


    581,219
    Counter by iLoveTheCode.com


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