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



  • I bookmarked this site...
    20,081

    iLoveTheCode.com
    Javascript > Javascript Tutorials How To Easy > Exit a For Loop in Javascript with Break

    Exit a For Loop in Javascript with Break



    To exit a for loop in Javascript, use break

    for(j=0;j<50;j++) {
    if (j == 44) {
    alert("We quit loop!");
    break;
    }
    else {
    document.write(j + " ");
    }
    }


    -We created the variable j as part of our for loop.
    -We said if j equals 44, put up and alert box and BREAK or exit the loop.
    -We said else print j which is our incrementing number.



    Free Copy and Paste Javascript Code:

    <script type="text/javascript">
    <!--
    for(j=0;j<50;j++) {
    if (j == 44) {
    alert("We quit loop!");
    break;
    }
    else {
    document.write(j + " ");
    }
    }
    -->
    </script>


    Resources:
    If, Else If, and Else in Javascript
    Opening an Alert Box in Javascript
    PRINT to Browser with document.write Command in Javascript



    Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
    Previous Article: Create a Function in Javascript
    Next Article: Write a For Loop in Javascript





    Dreamweaver CS3Dreamweaver CS3

    David McFarland

    New $29.69

    Pro CSS and HTML Design ...Pro CSS and HTML Design Patterns

    Michael Bowers

    New $29.69

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

    Eric Freeman, Elis...

    New $26.39

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

    Elizabeth Castro

    New $23.09

    CSSCSS

    Eric Meyer

    New $29.69

    CSS MasteryCSS Mastery

    Andy Budd, Simon C...

    New $23.09

    jQuery in ActionjQuery in Action

    Bear Bibeault, Yeh...

    New $26.39

    JavaScriptJavaScript

    David Flanagan

    New $31.49


    Of Interest:
  • And, Or, Equal, Not Equal, Greater Than, Less Than in Perl
  • Exit a Loop with Last
  • Add to the Beginning of an Array with Unshift in Perl
  • Renaming a File with Perl's RENAME Function
  • Javascript Referrer
  • Javascript Italics Text
  • PRINT to Browser with document.write Command in Javascript
  • Javascript Subscript Text
  • Make Strikethrough Text Using HTML
  • HTML Color Codes
  • HTML Body Tag
  • HTML Forms

  • More Articles:
  • Delete a File Using unlink in Perl
  • To Reverse an Array in Perl
  • INCREMENT and DECREMENT a Variable in Perl
  • Matching at the Beginning and End
  • onClick Javascript
  • Passing an Argument or Variable to a Javascript
  • Use innerHTML to Change Text on a Page
  • Setting a Cookie using Javascript
  • Use OnMouseOver in Javascript
  • HTML Underline Text
  • Make Italic Text Using HTML
  • HTML Title Tag
  • HTML Forms

  • 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


    316,821
    Counter by iLoveTheCode.com


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