Velocity Reviews > For Loops

# For Loops

Gregc.
Guest
Posts: n/a

 08-30-2006
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

Randy Webb
Guest
Posts: n/a

 08-30-2006
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/

Dr John Stockton
Guest
Posts: n/a

 08-31-2006
JRS: In article <(E-Mail Removed). com>,
dated Tue, 29 Aug 2006 17:27:07 remote, seen in
news:comp.lang.javascript, Gregc. <(E-Mail Removed)> posted :

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

--
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.

Gregc.
Guest
Posts: n/a

 08-31-2006

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

Gregc.
Guest
Posts: n/a

 09-01-2006

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.