By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,174 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

For Loops

P: n/a
Hi

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?

Greg

Aug 30 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Gregc. said the following on 8/29/2006 8:27 PM:
Hi

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?
Yes.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 30 '06 #2

P: n/a
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.
Aug 31 '06 #3

P: n/a

Dr John Stockton wrote:
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.
Hi

what does IMHO mean?

Greg

Aug 31 '06 #4

P: n/a
"Gregc." <gr*********@bigpond.comwrote in news:1157063021.499358.280480
@m73g2000cwd.googlegroups.com:
what does IMHO mean?
Learn to look things like this up on the web.

http://www.learnthenet.com/english/glossary/imho.htm

Aug 31 '06 #5

P: n/a

Jim Land (NO SPAM) wrote:
>Learn to look things like this up on the web.

http://www.learnthenet.com/english/glossary/imho.htm
Thanks for that.

Sep 1 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.