Sujet : Re: do { quit; } else { }
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.cDate : 04. Apr 2025, 21:18:45
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vsper4$b9vd$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
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.