From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: *** X-Spam-Status: No, score=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fac41,f66d11aeda114c52 X-Google-Attributes: gidfac41,public X-Google-Thread: 103376,f66d11aeda114c52 X-Google-Attributes: gid103376,public From: "Neil Wilson" Subject: Re: Building blocks (Was: Design By Contract) Date: 1997/09/30 Message-ID: <01bccdb8$29f54e30$4c18c90a@ntwneil>#1/1 X-Deja-AN: 276852803 X-NNTP-Posting-Host: aldur.demon.co.uk [158.152.11.163] References: <342A0AC6.2F2F@dynamite.com.au> <199709251320.PAA03585@basement.replay.com> <34316EC3.5B62@dynamite.com.au> Organization: Aldur Systems Ltd Newsgroups: comp.lang.ada,comp.lang.eiffel Date: 1997-09-30T00:00:00+00:00 List-Id: > In article <34316EC3.5B62@dynamite.com.au>, aebrain@dynamite.com.au wrote: > Yes, it's quite wrong to use a flag to terminate a while loop, instead of > just using exit with a loop. The idiom is, use an exit when the > termination depends on what you read, eg > [SNIP] > > The classic example is, read some integers until the user types in the value 0: > > loop > > Read (N); > exit when N = 0; > > > > end loop; This can be fixed by using a 'half unroll'. Eiffel supports this: loop file.read_integer while file.last_integer != 0 x.process (file.last_integer) file.read_integer end -- loop The introduction of the syntactically redundant 'loop' marker allows you to flag the start of the loop initialisation section (technically the section that sets up the loop invariant). The 'while' section is the loop itself (which has to maintain the invariant, move forward the variant and do the correct processing). Duplicating the 'read' command can be a bit of a pain, but in many instances initialising the structure can be a different operation from the actual iteration itself. -- Neil Wilson (neil at aldur dot demon dot co dot uk) Aldur Systems Ltd, UK