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=1.2 required=5.0 tests=BAYES_00,FROM_WORDY, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b50bc6538a649497 X-Google-Attributes: gid103376,public From: "Ken Garlington" Subject: Re: if statements Date: 2000/11/09 Message-ID: #1/1 X-Deja-AN: 691598145 References: <3A02CED4.520C2768@brighton.ac.uk> <3A078B6F.D34B024B@erols.com> <8ua3m1$bru$1@nnrp1.deja.com> <3A09A39F.2822C01B@cepsz.unizar.es> <8udce8$1qi$1@nnrp1.deja.com> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Complaints-To: abuse@flash.net X-Trace: news.flash.net 973775786 216.215.73.83 (Thu, 09 Nov 2000 07:16:26 CST) Organization: FlashNet Communications, http://www.flash.net X-MSMail-Priority: Normal NNTP-Posting-Date: Thu, 09 Nov 2000 07:16:26 CST Newsgroups: comp.lang.ada Date: 2000-11-09T00:00:00+00:00 List-Id: "Robert Dewar" wrote in message news:8udce8$1qi$1@nnrp1.deja.com... : I would write the above as: : : procedure Conditional_Swap (A, B : in out Integer) is : begin : if A < B then : declare : Temp : constant Integer := A; : begin : A := B; : B := Temp; : end; : end if; : end Conditional_Swap; This causes the *smaller* value to end up in A and the *larger* value to end up in B? Now I REALLY feel like a beginning student! Here's the problem statement as I understand it: : > "Exercise 4.1: Write an if statement which will swap the values of : > variables A and B if necessary so that the smaller value ends up in : > A and the larger value ends up in B." I always thought that a test such as "A < B" was true only if A was *already* smaller than B (in which case you shouldn't do a swap, right?). : I don't think that will make the plane crash :-) Well, if my requirement is to deploy a spin chute if the spin rate is larger than X degrees/sec, and I write if Spin_Rate < X then Deploy_Chute; end if; I certainly *might* crash a plane! :) : Though it : may be considered pedantic. As I say, bringing out the full : weight of careful style considerations for such a simple : program is overkill, but you have to start somewhere. Actually, I would also nitpick the choice of "Temp," when better options are available (Initial_A, or the really expressive Initial_Value_of_A).