Welcome to TalkGraphics.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2001
    Location
    Vancouver, BC, Canada.
    Posts
    55

    Default

    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.
    IP

  2. #2
    Join Date
    Jan 2001
    Location
    Vancouver, BC, Canada.
    Posts
    55

    Default

    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.
    IP

  3. #3
    Join Date
    Aug 2000
    Location
    Toronto, Ontario, Canada
    Posts
    432

    Default

    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>
    hth,
    Deep (just a guy)
    --
    Pradeep Kumar Nair, B.Math
    CTO
    9 Story Entertainment
    http://www.9story.com
    IP

  4. #4
    Join Date
    Jan 2001
    Location
    Vancouver, BC, Canada.
    Posts
    55

    Default

    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]
    IP

 

 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •