Sujet : Re: do { quit; } else { }
De : mikko.levanto (at) *nospam* iki.fi (Mikko)
Groupes : comp.lang.cDate : 18. Apr 2025, 08:30:10
Autres entêtes
Organisation : -
Message-ID : <vtsv22$2htsg$1@dont-email.me>
References : 1
User-Agent : Unison/2.2
On 2025-04-04 19:23:30 +0000, Thiago Adams said:
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*/
}
There should be a way to have multiple quits and way to selsct different
"else" blocks depending on which quit was executed.
But a new language feature is not necessary:
int quit = 0;
do
{
FILE f = fopen("file.txt", "r");
if (f == NULL) { quit = 1; goto next; }
/*success here*/
for (int i =0; i < 10; i++){
...
if (error) { quit = 2; goto next; }
}
}
switch (quit) {
{
case 1: { /* no file */ } break:
case 2: { /*some error*/ } break:
}
-- Mikko