Help with 'for' loop

This is a discussion on "Help with 'for' loop" within the JavaScript Forum section. This forum, and the thread "Help with 'for' loop are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jun 5th, 2007, 11:19
Junior Member
Join Date: May 2007
Location: Wales
Age: 19
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs down Help with 'for' loop

Can someone please explain the 'for' loop for me? i get so confused, here is an example for loop i found. What i don't understand is how they get the bits in bold:

PHP: Select all

for(0itd.lengthi++){ 

I know to some of you this may be easy, but I have learning difficulties, could someone explain it in very very easy steps please.

Last edited by karinne; Jun 5th, 2007 at 12:42. Reason: Please use [php]...[/php] tags when displaying PHP code.
Reply With Quote

  #2 (permalink)  
Old Jun 6th, 2007, 10:38
Junior Member
Join Date: May 2007
Location: Wales
Age: 19
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Help with 'for' loop

What is with the edit lol, that is not PHP, it's a JavaScript loop
Reply With Quote
  #3 (permalink)  
Old Jun 6th, 2007, 11:02
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Help with 'for' loop

I'm confused about your PHP reference, but in Layman's terms, it means.

The variable 'i' is set to zero. i = 0;

So long as the variable is less than the number of items in the array, 'td', 'i' will still keep on running the loop.

i++ means the number 'i' is plus one.
Reply With Quote
  #4 (permalink)  
Old Jun 6th, 2007, 11:34
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,619
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: Help with 'for' loop

to complement Ryan's answer, the official definition of a Javascript for loop is...
for( INITIALIZE, CONDITION, INCREMENT ){
// ... do stuff
}

INITIALIZE: a statement executed before the loop starts
This is usually used to declare a counter to be used in the loop
CONDITION: an expression that evaluates to either true or false
This is tested at the end of every cycle, false indicates "stop looping"...
INCREMENT: a statement to be executed at the end of every cycle.
This is usually used to increment the counter (eg.: add 1)

Now tell me, what the hell did you mean by this?
What i don't understand is how they get the bits in bold

If you mean you saw the code somewhere and some words (such as for) were in bold, this is called syntax highlighting. It makes it easier for programmers to read the code and identify special commands. 'How they make it bold' would be too much for you to understand at this stage...
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Reply With Quote
  #5 (permalink)  
Old Jun 7th, 2007, 13:22
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Help with 'for' loop

Nice explanation Spinal I kind of have a 'need to know' relationship with JS. That is, if I need something to work, I do the research to figure out how I can get it to function properly. I'm hoping for the universal understanding someday.
Reply With Quote
Reply

Tags
help, loops, with

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Do a while loop once? Jack Franklin PHP Forum 2 Feb 15th, 2008 11:07
The Loop (Again) Blake121 Free Web Site Critique 16 Sep 7th, 2007 13:57
The Loop V2 Blake121 Free Web Site Critique 8 May 15th, 2007 09:37
The Loop Blake121 Free Web Site Critique 5 May 1st, 2007 14:25
Loop??? tazek0 Classic ASP 0 Jan 27th, 2006 07:38


All times are GMT. The time now is 22:28.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43