Increment Twice in For loop

This is a discussion on Increment Twice in For loop within the C++ Programming forums, part of the General Programming Boards category; Rather than incrementing p by 1 for each iteration how would I go about incrementing p by 2 each time...thanks ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    12

    Increment Twice in For loop

    Rather than incrementing p by 1 for each iteration how would I go about incrementing p by 2 each time...thanks for your help. for(int p = 0; p < total_words; p++)

  2. #2
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186
    Code:
    (int p = 0; p < total_words; p+=2)
    p+=2 is the same thing as p = p + 2
    the best things in life are simple.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Also, not in response to your original question, you can do other things with for loops, such as:

    Code:
    x = 12; // or some arbitruary value
    
    for( int i = 0; i < 10; i++, x++ )
    {
         // Code...
    }

  4. #4
    Registered User JasonLikesJava's Avatar
    Join Date
    Mar 2002
    Posts
    175

    Talking

    Well, you could try it and see what happens.....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Increment / Decrement Operators - Help
    By shyam168 in forum C Programming
    Replies: 6
    Last Post: 03-29-2006, 08:24 PM
  2. How do I increment printf hex characters?
    By gechno in forum C Programming
    Replies: 2
    Last Post: 05-24-2004, 05:33 PM
  3. increment IP addresses - newbie Q.
    By webwesen in forum C Programming
    Replies: 6
    Last Post: 09-09-2003, 08:25 AM
  4. Post increment and pre increment help
    By noob2c in forum C++ Programming
    Replies: 5
    Last Post: 08-05-2003, 03:03 AM
  5. low value, high value and increment
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 11-25-2001, 08:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21