• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

increas value in for loop

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
Ocrana
Asked:
Ocrana
1 Solution
 
käµfm³d 👽Commented:
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
 
farzanjCommented:
Or
i+=300 instead of i+300
0
 
Subrat (C++ windows/Linux)Software EngineerCommented:
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
 
Sinisa VukCommented:
even better there can be ....

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

Open in new window

0
 
käµfm³d 👽Commented:
@sinisav

That approach was mentioned above  : )
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now