SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding more then one number ?

    If ++ as in num++ added a number how do you add 2,3,4 etc numbers ?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by SiberianHuskey View Post
    If ++ as in num++ added a number how do you add 2,3,4 etc numbers ?
    This is a good example of why ++ should not be used, and that += should be used instead.

    For example:

    Code javascript:
    var i;
    for (i = 0; i < 10; i += 1) {
        ...
    }

    If you want to add 3 instead, you can then change the += 1 to instead be += 3


    Code javascript:
    var i;
    for (i = 0; i < 10; i += 3) {
        ...
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see thanx. I'm still grasping the concept of using a variable i.


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
  •