?
Solved

increas value in for loop

Posted on 2012-08-28
5
Medium Priority
?
339 Views
Last Modified: 2012-09-29
Hello,

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

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

}
?
Ingo
0
Comment
Question by:Ocrana
5 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 38343764
Yes, just fix the last expression to do an assignment.

i.e.

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

Open in new window

0
 
LVL 31

Expert Comment

by:farzanj
ID: 38343815
Or
i+=300 instead of i+300
0
 
LVL 9

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

0
 
LVL 75

Expert Comment

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

That approach was mentioned above  : )
0

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