comp.lang.ada
 help / color / mirror / Atom feed
* Case statements in sane languages
@ 1990-03-19 15:49 Dale Worley
  1990-03-19 19:38 ` Mario O. Bourgoin
  0 siblings, 1 reply; 3+ messages in thread
From: Dale Worley @ 1990-03-19 15:49 UTC (permalink / 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...

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1990-03-20 16:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1990-03-19 15:49 Case statements in sane languages Dale Worley
1990-03-19 19:38 ` Mario O. Bourgoin
1990-03-20 16:02   ` Case statements: Error in my reply Mario O. Bourgoin

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