Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: After doing a lot of the problems on codingbat.com
Date: Thu, 02 Apr 2020 19:22:00 -0700
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <861rp5pauv.fsf@linuxsc.com>
References: <2f146b5c-e025-46ef-af7b-7c328c9f4206@googlegroups.com> <20200227200243.157a5e51fe7577f22aa37378@g{oogle}mail.com> <66Y5G.466396$Uz.23163@fx32.am4>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="764a289b4fffae23755ccdbd2c0254f8"; logging-data="17123"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/vn6gM1+HJjwDysDlVGjmjPCAwRWQ2u94="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:wv/5u1kvL4r0KfOK51y8mn5GWRI= sha1:A8wwyLyQX/NBQEJvo1zppz4ehP4=
Xref: csiph.com comp.lang.c:150969
Bart writes:
> On 27/02/2020 19:41, James Kuyper wrote:
>
>> On Thursday, February 27, 2020 at 12:02:53 PM UTC-5, Anton Shepelev wrote:
>>
>>> chad:
>>>
>>>> I've come to this horrible realization that I don't
>>>> understand a for loop as well as what I thought I did.
>>>
>>> Just don't abuse the for loop, cramping all kinds of
>>> unrelated code into its control expressions. ...
>>
>> I'm in full agreement with that.
>>
>>> ... Always use\
>>> it as a loop with a counter:
>>
>> But I can't agree that there's anything wrong with using any of the
>> following constructs:
>>
>> for(unsigned mask = 0x8000; mask; mask >>=1)
>>
>> for(Node* node=head; node; node = node->next)
>>
>> The first three user-controlled parts of a for-statement should be
>> reserved for loop-control, but there's many different ways to handle
>> loop control.
>
> unsigned mask = 0x8000h
> while (mask) {
> body;
> mask >>= 1;
> }
>
> Node * node = head;
> while (node) {
> body;
> node = node->next;
> }
It appears someone has a severe case of Old Dog syndrome.