Ok, first of all, sorry if this is vague and/or poorly worded; I am not much of a programmer really! If anything needs clarifying or I've made a mistake please let me know, and thank you in advance :)
In my program I have a function, which I shall call constrict() here, just for the sake of ease. This is what I would like it to do:
1 2 3 4 5 6 7 8 9 10
|
void constrict(int i, int j) {
if( (i - 1)%x != 0 ) {
if( (i - 2)%x != 0 ) {
etc etc. until...
if( (i - j)%x != 0 ) {
foo();
}
}
}
}
|
I know that x hasn't been defined and all that, but that's not the part I'm asking about, it's simply the repetition of the if statements of (i - a) where (a = 1; a <= j; a++)
I tried
1 2 3 4 5 6 7
|
void constrict(int i, int j) {
for (int a = 1; a <= j; a++) {
if( (i - a)%x != 0 ) {
foo();
}
}
}
|
but that clearly isn't right, because that evaluates the if statement for a = 1, and if it is true, then does foo(), then evaluates it again for a = 2, then does foo() again. this is not what I want!
I want it to check for a = 1, and if that is true then check for a = 2, etc. and only do foo() after all values of a from 1 to j have been checked. basically, what I posted in the first code box.
How do I achieve this? Help!