Re: Is getopt() standard C? etc.

From: Runtime (spam_at_heliopause.nu)
Date: 01/30/04


Date: Fri, 30 Jan 2004 14:44:27 -0000

In other news, José de Paula <jose_de_paula@ig.com.br> typed:
> Another doubt: I have a switch inside a while loop; is there a way to
> break out of the loop from the switch without using goto? I mean:
>

I'd do:

> while(chr = fgetc(inputfile))
> {

        int should_break_out = 0;

> switch(chr)
> {
> case 'a': case 'b':
> do_one_stuff(chr);
> break;
> case 'c': case 'd':
> do_some_other_stuff(chr);
> break;
> case 'e': case 'f':
> do_stuff(chr);
> break;
> default:

        should_break_out = 1;
        break;
> } /* end switch */

    if( should_break_out )
        break;

> do_even_more_stuff_here();
> } /* end while */
>
> Is there a way to get out of the while (i.e., skipping the
> "do_even_more_stuff_here();" part) without using this goto?
>

-- 
runtime


Relevant Pages

  • Re: acceptable use of goto?
    ... loop, forward within the loop at various points, then forward out of ... Then you give every statement a label. ... No goto statements. ... Then I build a framework (of if or switch statements) to eliminate the ...
    (comp.lang.c)
  • Re: Is getopt() standard C? etc.
    ... but it is part of POSIX (which is OT in this newsgroup). ... > break out of the loop from the switch without using goto? ... say goto start which is the start of the while loop). ... just fine as it doesnt have special meaning inside the switch. ...
    (comp.lang.c)
  • Re: a goto command???
    ... I treat goto like I treat eval in MATLAB. ... This saves a comparison operation on each loop iteration. ... which uses the switch technique outlined above but wrapped in macros to implement a lightweight stackless threading model. ...
    (comp.soft-sys.matlab)
  • Re: break inside of case- statement inside of loop
    ... Is it possible to break out of the for loop from inside of one case- ... break only gets you out of the smallest enclosing switch or loop. ... Or you could use goto: ... -Beej--4am...hopefully I didn't screw that answer up too bad. ...
    (comp.lang.c)
  • cant get out of infinite while loop
    ... To get into the infinite loop, I write to a file the "on" status ... writing switch on ... ready to sleep for 10 seconds ... or die "Problem passing files to the bridge directory...$!"; ...
    (comp.lang.perl.misc)