Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5

Thread: Loops explained

  1. #1
    Member jwind's Avatar
    Join Date
    Nov 2010
    Location
    On a mac
    Posts
    76
    Member #
    24894
    Liked
    4 times
    I'm really putting an effort to become fully literate in javascipt. Not just a tweaker/copy and paster.

    Any recommendations on resources that really break down and simplify the various types of loops, their structure and executions aside from the w3schools site. Getting my head around loops is a bit of a stumbling block for me.

  2.  

  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    Javascript Tutorial - Intro

    These guys are usually pretty helpful to people.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  4. #3
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    As I understand it, there are basically two kinds of loops


    for loops (counter-controlled loops) - keeps going until a previously set limit is reached
    ......initialization ....condition ... incrementation
    for (initial counter; condition; increment counter)
    {
    code to execute (this is the stuff that repeats)
    }

    e.g.

    for ($counter=1; $counter<=100; $counter++)
    {
    print $counter<br />;
    }

    while loops (sentinel-controlled loops) -where a condition is set, and the program checks to see if the condition still applies (is true).The loop will keep going as long as the condition applies, then stops.
    e.g.

    $counter = 1;
    while ( $counter<=100)
    {
    print $counter<br />;
    $counter++;
    }
    Both of the above loops will give you the same results.



    For more detailed explanation, try this - Javascript Tutorial - For Loop
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!

  5. #4
    Senior Member paintingtheweb's Avatar
    Join Date
    Jul 2007
    Location
    Las Vegas
    Posts
    128
    Member #
    15503
    Actually, technically there are 3 types. for loop, do loop, and while loop. The do and while are almost identical except that using the do syntax, the code inside the loop will execute 1 time no matter what, even if the condition at the end doesn't match the criteria necessary.

  6. #5
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    You're right. I have never had occasion to use a do loop and so I'd forgotten about it.
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:31 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com