Arithmetic operation within FOR loop

 

Hi Everyone! Just seeking very quick help with a piece of code that i suspect is the source of errors in my program. Is it OK to use an arithmetic operation within "for" loop as a condition???

Foe example:

for(int i=k; i<k+21; i++)

{

statements.


}

where "k" had been predefined.

Any help will be highly appreciated. Thanks.

 
Why do you think it wouldn't be?
 
Kenneth Njuguna:

Hi Everyone! Just seeking very quick help with a piece of code that i suspect is the source of errors in my program. Is it OK to use an arithmetic operation within "for" loop as a condition???

Foe example:

for(int i=k; i<k+21; i++)

{

statements.


}

where "k" had been predefined.

Any help will be highly appreciated. Thanks.

Are you looking for the statement above a a quick example or you have a full code?
If you have the full code then the K should be predefined some where in the code
 

Kenneth Njuguna:

Hi Everyone! Just seeking very quick help with a piece of code that i suspect is the source of errors in my program. Is it OK to use an arithmetic operation within "for" loop as a condition???

Foe example:

for(int i=k; i<k+21; i++)

{

statements.


}

where "k" had been predefined.

Any help will be highly appreciated. Thanks.


If there are errors, I assume, it's a problem in the logic of your statements. ;)

 
Kenneth Njuguna:

Hi Everyone! Just seeking very quick help with a piece of code that i suspect is the source of errors in my program. Is it OK to use an arithmetic operation within "for" loop as a condition???

Foe example:

for(int i=k; i<k+21; i++)

{

statements.


}

where "k" had been predefined.

Any help will be highly appreciated. Thanks.


Not a problem I've seen functions be used before.

for(int i=k; i<OrdersTotal(); i++)

And if you can use a function a little bit of arithmetic would be child's play.

 
John Davis:

Not a problem I've seen functions be used before.

And if you can use a function a little bit of arithmetic would be child's play.


Thanks everyone for the input. Indeed the errors are within the statements block. 

 

Without a doubt one of the most helpful online communities and much appreciated for/to everyone!!!

Reason: