Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c    |    Meh, in C you gotta define EVERYTHING    |    243,242 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 241,251 of 243,242    |
|    Anton Shepelev to All    |
|    Re: do { quit; } else { }    |
|    08 Oct 25 14:14:58    |
   
   From: anton.txt@g{oogle}mail.com   
      
   Thiago Adams:   
      
   > What do you think of this control block?   
   > do   
   > {   
   > FILE f = fopen("file.txt", "r");   
   >   
   > if (f == NULL) quit; /*goes to else part*/   
   >   
   > /*success here*/   
   > for (int i =0; i < 10; i++){   
   > ...   
   > if (error) quit;   
   > }   
   >   
   > }   
   > else   
   > {   
   > /*some error*/   
   > }   
      
   I have come to the conclusion that lots of advanced and very   
   speficic control-flow structures are being invented to avoid   
   using `goto' -- a simple and generic solution, with the   
   additoinal bonus of keeping the semantically linear code   
   actually flat.   
      
   Your proposal is not bad: it is keeping the main code flat   
   and saves extracting the `do' part into a separate function   
   (to take advantage of `return`). The `else' keyword seems   
   misleading, because it is not strictly alternative to the   
   `do' part. Is it your purpose to re-use C's existing   
   keywords? If not, then consider `fail` instead of `quit`   
   and `onfail` instead of `else`. Also, `do' may be renamed   
   `failable', indicating a block with controlled failure.   
      
   P.S.: I am eternally unhappy with the control-flow mechanisms   
    in existing programming languages.   
      
   --   
   () ascii ribbon campaign -- against html e-mail   
   /\ www.asciiribbon.org -- against proprietary attachments   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca