Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #27155

Re: javascript loop problem

From Denis McMahon <denismfmcmahon@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: javascript loop problem
Date 2015-04-01 14:43 +0000
Organization A noiseless patient Spider
Message-ID <mfh068$k3r$1@dont-email.me> (permalink)
References <8f8b8bbd-fed1-4871-b3e4-e0b96abd3692@googlegroups.com>

Show all headers | View raw


On Tue, 31 Mar 2015 19:05:54 -0700, chrisb wrote:

>     var myaddresses = [['Cambridge', 100], ['Auckland',20],
>     ['Wellington',1], ['Taupo',35]];
> 
>     for (var x = 0; x < myaddresses.length-1; x++) {
>         /* do stuff */
>     }

Let's step through the loop.
myaddresses.length = 4

1st time round. x starts as 0. x is less than 3. 1 is added to x. x is 
now 1. The loop body executes with x = 1, myaddresses[x] = 
['Auckland',20].

2nd time round. x starts as 1. x is less than 3. 1 is added to x. x is 
now 2. The loop body executes with x = 1, myaddresses[x] = 
['Wellington',1].

3rd time round. x starts as 2. x is less than 3. 1 is added to x. x is 
now 3. The loop body executes with x = 1, myaddresses[x] = ['Taupo',35].

4th time round. x starts as 3. x is not less than 3. loop terminates.

You might like to look at the (admittedly non jquery) page here:

http://www.sined.co.uk/tmp/tasfire3.htm

-- 
Denis McMahon, denismfmcmahon@gmail.com

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

javascript loop problem chrisb@ctlsoft.com - 2015-03-31 19:05 -0700
  Re: javascript loop problem Richard Maher <maher_rjSPAMLESS@hotmail.com> - 2015-04-01 10:49 +0800
  Re: javascript loop problem "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-04-01 14:42 +0200
  Re: javascript loop problem Denis McMahon <denismfmcmahon@gmail.com> - 2015-04-01 14:43 +0000

csiph-web