From: | richard@cogsci.ed.ac.uk (Richard Tobin) |
Newsgroups: | comp.compilers |
Date: | Wed, 19 Jan 2011 14:51:16 +0000 (UTC) |
Organization: | HCRC, University of Edinburgh |
References: | 11-01-043 11-01-055 11-01-078 11-01-081 |
Keywords: | syntax, optimize |
Posted-Date: | 19 Jan 2011 11:04:08 EST |
August Karlstrom <fusionfile@gmail.com> wrote:
>> while(condition) {
>> pre;
>> if(something)
>> break;
>> post;
>> }
>If your pre and post statements refer to a loop invariant the
>precondition should be checked before the loop is entered and the
>postcondition should be unconditionally checked at the end of each
>turn.
No, they were just the statements before and after the break.
>With a "structured" ("goto-less") loop a human only have to look at
>the loop guard rather than skimming through all of its contained
>statements in order to know what will hold true when the loop is
>finished (if it ever finishes that is). To me that is an obvious
>advantage.
But the loop condition may be more complicated as a result of having
avoided the break. And knowing under what condition a loop is
finished is not the only thing a reader is concerned about. The
resulting unnaturalness of the loop body may outweigh that.
And of course, you don't have to use breaks and gotos even if
the language provides them.
-- Richard
Return to the
comp.compilers page.
Search the
comp.compilers archives again.