Results 1 to 2 of 2

Thread: A for loop beginner's question

  1. #1
    Join Date
    Mar 2013

    A for loop beginner's question


    In the following code :

    var result = 1;
    for (var counter = 0; counter < 10; counter = counter + 1)
    result = result * 2;

    I can't figure out what is the relationship between variables result and counter. It works, I know but I don't see how this is possible since there is no code assembling both variables together in a single operation.

    Hope I am being clear enough.


  2. #2
    Join Date
    Mar 2011
    There isn't a direct relationship between the variables 'result' and 'counter' in your script. They have separate purposes. The counter just keeps track of the number of times the loop is processed, and each time the loop is processed, 'result' is doubled.
    Rick Trethewey
    Rainbo Design

Thread Information

Users Browsing this Thread

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

Posting Permissions

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