increas value in for loop

Posted on 2012-08-28
Medium Priority
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 75

Accepted Solution

käµfm³d   👽 earned 2000 total points
ID: 38343764
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

ID: 38343815
i+=300 instead of i+300

Expert Comment

by:Subrat (C++ windows/Linux)
ID: 38343939
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 28

Expert Comment

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

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

Open in new window

LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38353813

That approach was mentioned above  : )

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

850 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