Arithmetic operation within FOR loop

To add comments, please log in or register
Kenneth Njuguna
206
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.

whroeder1
17943
whroeder1  
Why do you think it wouldn't be?
soubra2003
31841
soubra2003  
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
Roland Rick
19
Roland Rick  

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. ;)

John Davis
9536
John Davis  
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.

Kenneth Njuguna
206
Kenneth Njuguna  
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. 

Kenneth Njuguna
206
Kenneth Njuguna  

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

To add comments, please log in or register