increas value in for loop

Posted on 2012-08-28
Last Modified: 2012-09-29

is it possible to increase a value with more than 1 inside a for loop?

for(int i = 0; i<nCount;i+300){

Question by:Ocrana
    LVL 74

    Accepted Solution

    Yes, just fix the last expression to do an assignment.


    for(int i = 0; i<nCount; i = i+300){

    Open in new window

    LVL 31

    Expert Comment

    i+=300 instead of i+300
    LVL 8

    Expert Comment

    by:Subrat (C++ windows/Linux)
    yes, it's possible. In your code, you r doing i+300, which doesn't have any impact upon the execution of for().
    If you want value of i should be incremented in steps of 300, then you should say something
    like i+=300 or i = i + 300, as already mentioned by other experts.

    Really i' m not understanding why this thing came into your mind. I hope you found that your code isn't behaving as per your wish. This is because, by saying i+300, value of i is not incrementing. To do that you have to assign it to variable i as said above.
    LVL 25

    Expert Comment

    by:Sinisa Vuk
    even better there can be ....

      for(i=0; i<nCount; i+=300){
        i += 250;

    Open in new window

    LVL 74

    Expert Comment

    by:käµfm³d 👽

    That approach was mentioned above  : )

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
    C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (…
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now