quote:
Originally posted by SmokingCookie
Hey, I'm a serious n00b with the for() statement (it just doesn't make any sense to me )
Well, I think I have some things to experiment with for tonight
It's quite simple in fact.
- The first bit (before your first semi-colon ";") is the initial statement. This is what will be executed at the beginning of your loop, and will only be run once. In most cases, you'll want to declare variables used for looping through arrays, enumerators,...
In our case, we define an Enumerator and a numeric variable to keep track of the counting.
- The second bit (between your semi-colons) is the conditional statement. Here, you have to put one condition (of course you can use && or || operators) which has to be checked after each loop, including the first one. If this is true, the loop will continue. If not, the loop will end.
In our case, we make sure that we don't go past the end of the enumerator.
- The last bit (after the second semi-colon) is the incremental statement. This will be executed after each loop, before the conditional statement is checked again for the next loop. It is normally used to increase the indexes, but in theory you can put anything here.
In our case, we move the Enumerator to the next item and increase the numeric index by one.
Play around with it, you'll get the hang of it quite fast. In 90% of the cases, it's always the same type you'll use:
code:
for(var i = 0; i < MAX_INDEX; i++) { ... }
where MAX_INDEX can be "SomeArray.length" for arrays, "PlusWnd.LstView_GetCount('SomeListView')" for window list-view controls,... it all depends of the particular case you're dealing with.