JRS: In article <11**********************@74g2000cwt.googlegroups. com>,
dated Tue, 29 Aug 2006 17:27:07 remote, seen in
news:comp.lang.javascript, Gregc. <gr*********@bigpond.composted :
>I am not sure you guys can help me, but here it goes. am having
trouble understanding for loops. If I have a loop that says:
var coffee = new Array();
coffee ["mixedblend"] = 5.50;
for (c in coffee)
{code goes here}
That for saying while there is a c in coffee, then conduct the code.
Is that a correct interpretation?
No.
Consider and try the following
var coffee = new Array();
coffee ["mixedblend"] = 5.50;
coffee ["grots"] = 1.50;
for (c in coffee) alert (c + " costs " + coffee[c])
IMHO, it is generally better to use Array only for numeric indices, and
the above could start var coffee = {} // empty Object.
The ordering apparent in coffee by for (c in coffee) is undefined.
You should use var c; and, as that is essentially an indexing operation,
I'd use J instead of c.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.