Case statements in sane languages

Dale Worley worley at Compass.COM
Tue Mar 20 01:49:40 AEST 1990


    From: sanders at sanders.austin.ibm.com (Tony Sanders)

    How do you do this in ADA?

	switch(n) {
	  case 0:
	    count++;
	  case 1:
	    ocount++;
	  case 2:
	    printf("%d %d\n",count,ocount);
	    break;
	  default:
	    printf("unknown n\n");
	    break;
	}

    See how I left out the breaks on purpose.

    In ADA you wouldn't be able to do this without duplicating either the
    case-expression (they aren't always simple numbers) or the statements.

In this case, duplicating the statements wouldn't be hard enough to
worry about.  If the bodies of the cases were large enough to make it
hard, you can write a local procedure, and just call it from several
cases.  (Since Ada has nested procedures, you can write a procedure
that has access to local variables.)

    The 11th commandment: "Thou shalt use lint"

In Ada (or any sane language), "Lint" is called "the compiler".

Dale Worley		Compass, Inc.			worley at compass.com
--
Why are you RUNNING?  Cerebus just wants to KILL you a little...



More information about the Comp.lang.c mailing list