elkingrey Posted November 30, 2012 Share Posted November 30, 2012 Can somebody point me to where the whole i variable gets explained in detail? I've been going through all of the courses at w3schools starting from the beginning(HTML) and have made it all the way to XML, where I am now. I know in earlier sections they bring up examples like (i=x,i<x,i++) and stuff, but I just never fully understood where they are getting all that from. When I first came across it I just decided to accept it for what it was, hoping I would gain a greater understanding later on, but here I am at XML and I still don't understand fully the rules governing i and increments and such. Any help would be much appreciated. Link to comment Share on other sites More sharing options...
Ingolme Posted November 30, 2012 Share Posted November 30, 2012 It could be anything. It doesn't necessarily have to be called "i". It's part of Javascript's for() loop and doesn't have anything to do with XML. Perhaps you're reading the XML DOM tutorial. The prerequisite to reading this tutorial is to have read the Javascript tutorial first. Read this page, don't just glance at it or you won't get what's going on: http://www.w3schools.com/js/js_loop_for.asp Link to comment Share on other sites More sharing options...
elkingrey Posted November 30, 2012 Author Share Posted November 30, 2012 I read it thoroughly the first time. I still didn't understand it. Rereading it however I see this: Statement 1 is executed before the loop (the code block) starts.Statement 2 defines the condition for running the loop (the code block).Statement 3 is executed each time after the loop (the code block) has been executed. and it makes more sense now. This sort of clears things up for me. Thanks for linking to that specific page! Link to comment Share on other sites More sharing options...
thescientist Posted December 11, 2012 Share Posted December 11, 2012 (edited) the most likely reason that the variable "i" is used is because loops are typically used with arrays. each member of an array can be referenced by its index, which is what one is doing when the loop over an array, i.e. var letters = ['a','b','c'];for(var i = 0; i < l; i++){ alert('the letter at index [' + i + '] is => ' + letters[i]);}; and remember, that arrays start at 0. Edited December 11, 2012 by thescientist Link to comment Share on other sites More sharing options...
Ingolme Posted December 12, 2012 Share Posted December 12, 2012 the most likely reason that the variable "i" is used is because loops are typically used with arrays. each member of an array can be referenced by its index, which is what one is doing when the loop over an array, i.e.var letters = ['a','b','c'];for(var i = 0; i < l; i++){ alert('the letter at index [' + i + '] is => ' + letters[i]);}; and remember, that arrays start at 0. I believe "i" stands for "iterator" Link to comment Share on other sites More sharing options...
thescientist Posted December 13, 2012 Share Posted December 13, 2012 Most of colleagues go with index. wikipedia goes as far back as the FORTRAN days and states it could be because they were integers.http://en.wikipedia.org/wiki/Loop_counter either way, it's a interesting discussion. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now