elkingrey 0 Posted November 30, 2012 Report 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. Quote Link to post Share on other sites
Ingolme 1,020 Posted November 30, 2012 Report 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 Quote Link to post Share on other sites
elkingrey 0 Posted November 30, 2012 Author Report 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! Quote Link to post Share on other sites
thescientist 231 Posted December 11, 2012 Report 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 Quote Link to post Share on other sites
Ingolme 1,020 Posted December 12, 2012 Report 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" Quote Link to post Share on other sites
thescientist 231 Posted December 13, 2012 Report 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. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.