Sujet : Re: C23 thoughts and opinions
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.lang.cDate : 04. Jun 2024, 03:20:43
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v3ltlr$48om$16@dont-email.me>
References : 1 2 3 4 5 6 7 8
User-Agent : Pan/0.158 (Avdiivka; )
On Mon, 3 Jun 2024 23:43:00 +0100, bart wrote:
All that suggest sto me is that the language *needs* an explicit endless
loop!
I agree. Also it is common for a loop to have multiple exits, and I don’t
like treating one of them as a special “termination condition” above the
others, so I like to use “break” for all of them.
The “for” form not only caters for this, it allows handy initialization of
local variables that keep their value between loop iterations. E.g.
for (unsigned int i = length_of(array);;)
{
if (i == 0)
{
... not found ...
break;
} /*if*/
--i;
if (... array[i] matches what I want ...)
{
.. found ...
break;
} /*if*/
} /*for*/