-
I am sure people whith programming experience should know answer to the question.
Could you explain in human language the difference between pre-increment and post-increment operators.
After I read the examples in Flash5 help I got even more confused. I don't understand why i++ returns the value of i instead of i+1 and why in (Flash help) i++ in while loop is considered pre-increment operator.
<BLOCKQUOTE><font size="-1">quote:</font><HR>
Quote:
The following example uses ++ as a pre-increment operator with a while statement.
i = 0
while(i++ < 5){
// this section will execute five times
}
<HR></BLOCKQUOTE>
I know it should be very simple, I am just missing something [img]/infopop/emoticons/icon_redface.gif[/img]
Any help would be much appreciated.
-
I am sure people whith programming experience should know answer to the question.
Could you explain in human language the difference between pre-increment and post-increment operators.
After I read the examples in Flash5 help I got even more confused. I don't understand why i++ returns the value of i instead of i+1 and why in (Flash help) i++ in while loop is considered pre-increment operator.
<BLOCKQUOTE><font size="-1">quote:</font><HR>
Quote:
The following example uses ++ as a pre-increment operator with a while statement.
i = 0
while(i++ < 5){
// this section will execute five times
}
<HR></BLOCKQUOTE>
I know it should be very simple, I am just missing something [img]/infopop/emoticons/icon_redface.gif[/img]
Any help would be much appreciated.
-
Pre-increment increments the number BEFORE the operation has been performed. Post- does it AFTER the operation is performed. For example:
i=0;
while (i++ < 5) {
trace i;
}
would write:
0
1
2
3
4
whereas:
i=0;
while (++i < 5) {
trace i;
}
would write:
1
2
3
4
since the first loop would start at i+1 instead of i (in otherwords it increments i, THEN starts the loop - hence the term pre-increment).
Hopefully this makes it a little more clear!
hth,
Deep (just a guy)
<font face="arial" size="2">
Pradeep Kumar Nair, B.Math
Senior Web Designer
http://www.blab.com
ICQ: 39102360
</font>
-
Thanks, I have figured that out already. There is probably just a typo in the Macromedia help file.
Alex [img]/infopop/emoticons/icon_smile.gif[/img]