Deutsch   English   Français   Italiano  
<vsper4$b9vd$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: bart <bc@freeuk.com>
Newsgroups: comp.lang.c
Subject: Re: do { quit; } else { }
Date: Fri, 4 Apr 2025 21:18:45 +0100
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <vsper4$b9vd$1@dont-email.me>
References: <vspbjh$8dvd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 04 Apr 2025 22:18:45 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="a6f0cf8cc8f6e00e3b4b9168d0c49396";
	logging-data="370669"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19MWENFaJRN+1emmvMQFclb"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:5R+Dh8NemhAQcwiEOfAjMHoCDoc=
Content-Language: en-GB
In-Reply-To: <vspbjh$8dvd$1@dont-email.me>
Bytes: 2382

On 04/04/2025 20:23, Thiago Adams wrote:
>    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*/
>    }
> 

As a new language feature?

I think 'do {}' would be confused 'do {} while' (a parser - or a human - 
won't know this isn't a loop until the 'else' is seen. And then there's 
a possibility that that 'else' belongs to an 'if' but an omission or 
inclusion of a braces has screwed things up.

Perhaps a new keyword ('try' maybe) is better.

You'd also need to specify how nested do-else blocks will work. Or will 
'quit' (so you have a new keyword anyway) only work at this level?

What about chained versions: do {} else do {} else ...; I guess 'quit' 
will just go to the next else block rather than quit the whole chain?

Note that this can be emulated in C now using:

    if
    {
      goto quit001;
    }
    else
    {quit001:
    }

Perhaps what C needs is a way to do that jump without an explicit goto:

    if
    {
      quit001;
    }
    else
    {quit001:
    }

You can require that such jumps can only go forwards.