Liste des Groupes | Revenir à cl c |
On 2024-06-02, Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:I've always considered
for (;;)
preferable over
while (1)
Of course it is preferable. The idiom constitutes the language's
direct support for unconditional looping, not requiring that to be
requested by an extraneous always-true expression.
Using while (1) or while (true) is like i = i + 1 instead
of ++i, or while (*dst++ = *src++); instead of strcpy.
When Dennis Ritchie (if it was indeed he) chose for to be the
construct in which the guard expression may be omitted, so that it
may express conditional looping, he expressed the intent that it be
henceforth used for that purpose.
To continue to use while (1) after the proper utensil is provided is
like to eat with your hands instead of a fork.
Les messages affichés proviennent d'usenet.