Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: After doing a lot of the problems on codingbat.com Date: Fri, 28 Feb 2020 01:37:06 -0800 Organization: None to speak of Lines: 38 Message-ID: <871rqft5ml.fsf@nosuchdomain.example.com> References: <2f146b5c-e025-46ef-af7b-7c328c9f4206@googlegroups.com> <20200227200243.157a5e51fe7577f22aa37378@g{oogle}mail.com> <66Y5G.466396$Uz.23163@fx32.am4> <6e7cb40b-afaa-4c54-b445-6cbf407c0697@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="45d8797b4cf74f417b3a254c44fb9e68"; logging-data="9411"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+z7iGEPMpXbRFZ1XBXYs+1" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cancel-Lock: sha1:kgb1WFLN8FtpCZK1F6oarf7layc= sha1:bmBT+KLmyx9/lbbRE46JRs21kiY= Xref: csiph.com comp.lang.c:150328 Bart writes: > On 28/02/2020 00:40, James Kuyper wrote: [...] >> Frankly, the only reason I can imagine for finding the for() versions >> more confusing is a mindset that insists on interpreting them as >> equivalent to Fortan FOR loops, with unnecessary extra capabilities. > > Most of them will be. But enough won't be so that means having to > pause and analyse each one, even ones like 'for (int i=0; i which look like simple iteration at first but with minor deviances. > > Here are some wonderful examples from sqlite3: > [snip] > for(; (c=(*fmt))!=0; ++fmt){ > > With this last, is there any reason why this shouldn't have been a > simple while loop? If not, then why does C even bother having > while(c){} when someone can just write for(;c;){}? I have no problem with that for loop. I'm aware that you do, and I'm not interested in changing your mind. I'm just making you aware that some of us find the "for" version readable. Something like for (;c;){} should almost certainly be a while loop, but in the above example it's handy to put the ++fmt at the top of the loop rather than burying it at the bottom. (It would have been more for-like if fmt were initialized in the loop. Without context, I can't guess why that wasn't done.) -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips Healthcare void Void(void) { Void(); } /* The recursive call of the void */