Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #100593

Re: while loop vs do while loop reading from the file issue

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: while loop vs do while loop reading from the file issue
Date 2016-12-30 14:04 +1300
Message-ID <eclq4mFq0blU1@mid.individual.net> (permalink)
References (18 earlier) <kfneg0qwlfs.fsf@x-alumni2.alumni.caltech.edu> <b9478ce8-5425-4524-b8d3-a0dd5cd414f3@googlegroups.com> <ecleluFpuo9U9@mid.individual.net> <e2fbbf2c-e52f-4c8b-9cd8-8f901a273750@googlegroups.com> <o44bic$v4c$1@dont-email.me>

Show all headers | View raw


On 12/30/16 02:01 PM, BartC wrote:
> On 30/12/2016 00:46, Malcolm McLean wrote:
>> On Thursday, December 29, 2016 at 9:48:54 PM UTC, Ian Collins wrote:
>>> On 12/30/16 10:25 AM, Malcolm McLean wrote:
>>>>
>>>> You can't have a "loop and a half" and still have a structured program.
>>>> Sorry, that is abundantly clear to me. The result is not a totally
>>>> unstructured program, or a "bad" program necessarily, but one which
>>>> violates a property of structured programming, and essential property,
>>>> that each block have one point of entry and one point of exit.
>>>
>>> So something like
>>>
>>> while( something )
>>> {
>>>     if( doSomething() !=0 )
>>>       goto error;
>>>     doSomethingElse();
>>> }
>>>
>>> error:
>>>
>>> breaks that rule?
>>>
>> Exactly.
>>
>> The mistake a lot of people make is to think that since structured
>> programming is "good", "good" programs are structured (in the sense
>> intended) whilst bad programs are not.
>>
>> The while block has two point of exit. So not a "block" in structured
>> programming terms.
>
> Can't you just wrap the whole thing up in a block?
>
> {while (something){... goto error;...}; error:;}
>
> One entry point, one exit point.

The inner block is still a block.

-- 
Ian

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-29 13:25 -0800
  Re: while loop vs do while loop reading from the file issue Ian Collins <ian-news@hotmail.com> - 2016-12-30 10:48 +1300
    Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-29 16:46 -0800
      Re: while loop vs do while loop reading from the file issue Ian Collins <ian-news@hotmail.com> - 2016-12-30 13:51 +1300
        Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-29 17:22 -0800
          Re: while loop vs do while loop reading from the file issue Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-13 02:45 -0800
      Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-30 01:01 +0000
        Re: while loop vs do while loop reading from the file issue Ian Collins <ian-news@hotmail.com> - 2016-12-30 14:04 +1300
        Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-29 17:23 -0800
  Re: while loop vs do while loop reading from the file issue asetofsymbols@gmail.com - 2016-12-30 00:56 -0800
  Re: while loop vs do while loop reading from the file issue Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-13 02:41 -0800
    Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-13 09:59 -0800
      Re: while loop vs do while loop reading from the file issue Gareth Owen <gwowen@gmail.com> - 2017-01-13 18:48 +0000
        Re: while loop vs do while loop reading from the file issue Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-15 12:08 -0800
          Re: while loop vs do while loop reading from the file issue Gareth Owen <gwowen@gmail.com> - 2017-01-15 23:09 +0000
            Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2017-01-15 23:18 +0000
              Re: while loop vs do while loop reading from the file issue Gareth Owen <gwowen@gmail.com> - 2017-01-15 23:37 +0000
              Re: while loop vs do while loop reading from the file issue raltbos@xs4all.nl (Richard Bos) - 2017-01-18 11:32 +0000
                Re: while loop vs do while loop reading from the file issue Gareth Owen <gwowen@gmail.com> - 2017-01-18 21:25 +0000
      Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2017-01-13 11:54 -0800
      Re: while loop vs do while loop reading from the file issue Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-15 11:58 -0800

csiph-web