Solved

# increas value in for loop

Posted on 2012-08-28
Medium Priority
339 Views
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
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.

i.e.

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

LVL 31

Expert Comment

ID: 38343815
Or
0

LVL 9

Expert Comment

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

ID: 38353256
even better there can be ....

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

LVL 75

Expert Comment

ID: 38353813
@sinisav

That approach was mentioned above  : )
0

## Featured Post

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.
###### Suggested Courses
Course of the Month16 days, 1 hour left to enroll