+ Reply to Thread
Results 1 to 5 of 5

Thread: JavaScript:Tutorial, Loops

  1. #1
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101

    JavaScript:Tutorial, Loops

    Introduction:-
    In this tutorial I will show you the two types of loops there are in JavaScript.

    Explanation:-
    You might say where is the code? He is already explaining without the code?
    Well this time I think that its better if the Explanation comes before the Code

    There are 2 types of loops:-
    • For Loops
    • While Loops

    For Loops:-
    The For Loops are used in this way

    Code:
    for (something)
    {
    do something else
    }
    While Loops:-
    The While Loops are used in this way:-

    Code:
    while (something)
    {
    Do something else
    }
    Solution:-
    Now that you had an idea of the basic usage of the loops here are some practical codes:-

    For Loops:-

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    var lp=1;
    for (lp=0;lp<15;lp++)
    {
    document.write ("For Loop "+lp+"<BR>");
    }
    </SCRIPT>
    Note: lp is a variable, and until that variable has reached the value of 14 (<15) the loop will go on

    While Loops:-

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    var lp=0;
    while (lp<15)
    {
    document.write ("While Loop "+lp+"<BR>");
    lp++;
    }
    </SCRIPT>
    Note: lp is a variable, and while that variable is <15 the loop will go on

    A Preview:-
    None

    Conclusion:-
    As Always Feedback is welcome! In the next tutorial I will tell you how to exit from the loop. I don't think that this needs any source code..
    Last edited by TcM; 12-06-2006 at 01:14 PM.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Ronin is offline Programming Professional
    Join Date
    Apr 2006
    Posts
    309
    Rep Power
    24
    Nice tutorial. I need to learn JavaScript sooner or later and these (the ones that you've been posting) will help a lot!

  4. #3
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101
    Quote Originally Posted by Ronin View Post
    Nice tutorial. I need to learn JavaScript sooner or later and these (the ones that you've been posting) will help a lot!
    I'm happy these helped you I will be posting more and more.. be sure to see my next tutorial ( will be posted very soon ) on how to break out of a loop...

  5. #4
    castanza88 is offline Newbie
    Join Date
    Dec 2006
    Posts
    5
    Rep Power
    0

    Javascript tutorials

    good breakdown of code, and examples...wish more people did that...

  6. #5
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101
    Quote Originally Posted by castanza88 View Post
    good breakdown of code, and examples...wish more people did that...
    Thanks... for your feedback

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. JavaScript:Tutorial, Redirect URL
    By TcM in forum JavaScript Tutorials
    Replies: 5
    Last Post: 01-17-2011, 04:49 AM
  2. JavaScript:Tutorial, Confirmation Box
    By TcM in forum JavaScript Tutorials
    Replies: 5
    Last Post: 11-07-2009, 08:13 PM
  3. TI-BASIC Tutorial - Loops
    By exfyre in forum Tutorials
    Replies: 2
    Last Post: 08-29-2009, 06:42 AM
  4. JavaScript:Tutorial, Prompt
    By TcM in forum JavaScript Tutorials
    Replies: 2
    Last Post: 01-21-2007, 01:58 AM
  5. JavaScript:Tutorial, Break Out Of Loops
    By TcM in forum JavaScript Tutorials
    Replies: 0
    Last Post: 12-08-2006, 03:35 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts