View Full Version : increment question
Rupert
11-22-2001, 04:15 AM
Easy question - Just looking through some of the samples at JoshDura.com (nice one by the way Josh!) and I noticed he is using ++i - does this work the same as i++ ?
Cheers, Rupert
Jesse
11-22-2001, 05:11 AM
preincriment (++i) Vs. post incriment (i++) is a kinda complicated thing to expalain. they aren't the same. the best way to look at it is like this:
for (i=0; i<10; i++) {
familiar bit of code right? i is set to zero, tested against the less than 10 condition, then the code in the loop is run, and i is incrimented.
for (i=0; i<10; ++i) {
looks the same but really isn't. i is set to zero, incrimented, tested against the less than 10 condition, then the code in the loop is run...
it's more applicable in languages like C where you're incrimenting pointers before you dereference them and stuff... but yeah. I hope that almost explained it :)
Rupert
11-22-2001, 05:21 AM
Thanks Jesse, I think I get how it "works" now, but I'm not quite able to grasp what kind of practical application you might use it for! Perhaps I'll pretend I didn't see it... Cheers,
Rupert
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.