home bbs files messages ]

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,254 of 243,242   
   Thiago Adams to Anton Shepelev   
   Re: do { quit; } else { }   
   08 Oct 25 09:59:30   
   
   From: thiago.adams@gmail.com   
      
   On 10/8/2025 8:14 AM, Anton Shepelev wrote:   
   > 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.   
      
   The problem with goto is define a name and to find this name   
   on the source code. Is it up or down?   
      
   "break" "continue" fixes the problem of defining a name and   
   restrict our search to  "closest" iteration loop, we search   
   up.   
      
   "quit" here is similar of  "break" and "continue".   
      
      
   > 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.   
   >   
      
   I realized a problem with this keyword selection "do { }else {}".   
   The problem is that using "do" we don't what kind of "do" where are   
   until we find the "else" that is too late.   
      
   So, we need a different keyword to start the block.   
      
   Alternatives:   
      
   try {   
       throw; //error   
       quit;  //early success - exit without going to catch   
   }   
   catch {   
   }   
      
   --- 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