Liste des Groupes | Revenir à cl c |
bart <bc@freeuk.com> writes:I only recently noticed that the pattern was rather different from an upwards loop. For example, for a range of 0..N-1 inclusive the upper limit is usually written as N, with N-1 being something that a 1-based language is more likely to use.On 19/04/2025 20:54, Keith Thompson wrote:No, it's not. I didn't mean to imply that it was.bart <bc@freeuk.com> writes:>
[...]I don't understand why you're happy using a crippled looping[...]
mechanism, that is a PITA to use for the majority of iterating loops,
just so you have that flexibility for the whacky loops that are in the
minority, most of which can be trivially expressed with 'while'.
I agree. You don't understand. What confuses me is your complete
lack
of interest in trying to understand.
Many of us are happy using C's for loop because we don't consider
it to be crippled. It is not a PITA to use it for the majority of
iterating loops; we just use a very common coding pattern like
for (int i = 0; i < N; i ++) {
// ...
}
We can write "i --" if we want the loop to run in reverse,
That's not enough for it to run in reverse.
I'd be interested in aReally? It's such a simple example that I'm surprised you think you
complete example.
need my help. But ok :
for (int i = N-1; i >=0; i --) {
// ...
}
I wrote that off the top of my head. I then wrote and compiled a
program using it, and it worked.
A similar loop with an iteration variable of an unsigned type wouldJust insist on signed loop variables. Or if ints are 32 bits and start values are between 2**31 and 2**32, require an i64 loop variable.
fail because `i >= 0` is always true. I have some thoughts about
how to deal with that, but I'll leave that aside.
Les messages affichés proviennent d'usenet.