comp.lang.ada
 help / color / mirror / Atom feed
From: worley@Compass.COM (Dale Worley)
Subject: Case statements in sane languages
Date: 19 Mar 90 15:49:40 GMT	[thread overview]
Message-ID: <9003191549.AA01608@sn1987a.compass.com> (raw)


    From: sanders@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@compass.com
--
Why are you RUNNING?  Cerebus just wants to KILL you a little...

             reply	other threads:[~1990-03-19 15:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1990-03-19 15:49 Dale Worley [this message]
1990-03-19 19:38 ` Case statements in sane languages Mario O. Bourgoin
1990-03-20 16:02   ` Case statements: Error in my reply Mario O. Bourgoin
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox