From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT autolearn=no autolearn_force=no version=3.4.4 Xref: utzoo comp.lang.ada:3441 comp.lang.c:26871 comp.lang.misc:4434 Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!bloom-beacon!mintaka!ogicse!caesar.cs.montana.edu!uakari.primate.wisc.edu!aplcen!uunet!mcsun!sunic!enea!sommar From: sommar@enea.se (Erland Sommarskog) Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.misc Subject: Re: problems/risks due to programming language, stories requested Message-ID: <879@enea.se> Date: 13 Mar 90 22:11:18 GMT References: <1004@micropen> <8218@hubcap.clemson.edu> <1771@awdprime.UUCP> Followup-To: comp.lang.misc Organization: Enea Data AB, Sweden List-Id: I tried thrice mailing this guy, including the path(!) he gave in his signature. Couldn't IBM afford to be better connected? Tony Sanders (sanders@sanders.austin.ibm.com) writes: >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. Cross you heart, how often in practical programming do you write such code? And how often compared to normal switch statements where an easily elided break would introduce a simple bug? It might be that I never program in C, but I have never felt the need for a fall-through. Also, it seem more frequent that I first want to execute some common code and then split the cases further. In this case C's fall-throughs help you none. In Ada (please note, it's not all-capital) I would probably have written the above as: IF N = 0 THEN Count := Count + 1; END IF; IF N IN 0..1 THEN OCount := OCount + 1; END IF; IF N IN 0..2 THEN Put(Count, 10); Put(OCount, 10); New_line; ELSE Put_line("Unknown."); END IF; With a one-line statement for N = 2, I might have chosen to repeat some lines of code, if the CASE statement better had illustrated the problem. (And I would probably have made the same arrangements in C.) -- Erland Sommarskog - ENEA Data, Stockholm - sommar@enea.se