C - is it possible to decrement the max value of a for loop from within the for loop?
Posted
by hatorade
on Stack Overflow
See other posts from Stack Overflow
or by hatorade
Published on 2010-04-12T21:27:03Z
Indexed on
2010/04/12
21:33 UTC
Read the original article
Hit count: 298
for example:
void decrement(int counter) {
counter--;
}
int counter = 20;
for (int i = 0; i < counter; i++) {
for (int j = 0; j < counter, j++) {
decrement(counter);
}
}
ideally, what i'd like to see is the counter
var being decremented every time the for loop is run, so that it runs fewer than 20 iterations. but gdb shows that within decrement()
counter
is decremented, but that going back to the for loop counter
actually stays the same.
© Stack Overflow or respective owner