[C] for looping problem
I'm almost sure to be right about the following:
If you've got two variables, x and argc, (used for command-line input) and you want to make a loop where x will constantly be raised by one, started with value 1, until the value of argc is reached. To me, the most neat approach to do that is by using for: Code:
for ( x = 1 ; x == argc ; x++ ) Code:
int main(int argc, char **argv) |
Re: [C] for looping problem
This is the miskate you are making
Code:
for ( x = 1 ; x <= argc ; x++ ) |
So:
Code:
for ( x = 1 ; !(x == argc) ; x++) |
Sure, as well as:
Code:
for (x = 1; x != argc; x++) |
Thank you both.
|
Well, they're not quite the same.
Satan's will execute the loop so long as x is less than or equal to argc, while the other two examples will only execute when x is not equal to argc (meaning that when x is equal to argc, the loop will terminate before it goes through). |
True, but that only makes satan's code the better o the three. Because x is incremented by 1 the result in this case is the same.
|
All times are GMT -5. The time now is 06:42 AM. |