Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: while loop vs do while loop reading from the file issue Date: Fri, 16 Dec 2016 12:31:14 -0800 Organization: None to speak of Lines: 46 Message-ID: References: <52f1c174-6af1-4fda-9ff8-a5e2cf507b5f@googlegroups.com> <87bmwgpxbs.fsf@bsb.me.uk> <87mvg0o6hk.fsf@bsb.me.uk> <87a8bza8ly.fsf@bsb.me.uk> <87bmwf8d7a.fsf@bsb.me.uk> <87poku5ism.fsf@bsb.me.uk> <8760ml5v5k.fsf@bsb.me.uk> <37e325fb-4aa8-4c84-9bcd-c1aa790fadc7@googlegroups.com> <87zijw3cfs.fsf@bsb.me.uk> <10e036fc-93fb-4d99-ba8f-1bbd16448b8c@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="2210dc8e98a3c302beae7e7a325c3760"; logging-data="15326"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+luNQvCRfy9yuRqKLo8NrO" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:SMO2x6B0c25X6kZkC3jtsIVjfhs= sha1:xrxOs1OqyoyUN8QDrPfeiDsaRAU= Xref: csiph.com comp.lang.c:99684 Malcolm McLean writes: > On Friday, December 16, 2016 at 5:41:33 PM UTC, Keith Thompson wrote: >> Malcolm McLean writes: >> [...] >> > Really we want this (pseudo-code) >> > >> > nextline: >> > line = getline(); >> > if(line == endofdata) >> > goto endofdata; >> > processline(line); >> > goto nextline; >> > endofdata: >> > >> > but it's not structured. >> >> But it can be written in an equivalent structured form: >> > That's not really possible. > > Structured programming isn't about the notation you use for > the program, but the logical flow. To turn an unstructured > program into an equivalent one that is structured, you need > to rewrite it, not translate it. That's a quibble about the meaning of the word "structured". Whether it's strictly structured or not, I'd say that my equivalent version (which you inexplicably snipped): while ((line = getline()) != endofdata) { processline(line); } is more *nearly* "structured" than yours, and that it's much clearer (at least to someone reasonably familiar with C, and such readers are usually my only target audience for C code). Why exactly did you feel the need to post your version with goto statements? What point were you trying to make? -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"