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/07 Message-ID: <8mTN5.7821$pq3.603668@news.flash.net>#1/1 X-Deja-AN: 690778240 References: <3A02CED4.520C2768@brighton.ac.uk> <3A078B6F.D34B024B@erols.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 973603332 216.215.83.108 (Tue, 07 Nov 2000 07:22:12 CST) Organization: FlashNet Communications, http://www.flash.net X-MSMail-Priority: Normal NNTP-Posting-Date: Tue, 07 Nov 2000 07:22:12 CST Newsgroups: comp.lang.ada Date: 2000-11-07T00:00:00+00:00 List-Id: "Daniel Allex" wrote in message news:3A078B6F.D34B024B@erols.com... : procedure Swap ( A, B : in out Integer ) is : Temp : Integer := 0; : begin : if A <= B then : Temp := A; : A := B; : B := Temp; : end if; : end; : : : sc297 wrote: : : > can anyone show me an if statement that will swap the values of A and B, : > if A is the greater value Now *I* feel like a beginning Ada student! Doesn't the proposed solution swap A and B if A is *not* the greater value? And why is Temp assigned an initial value of 0? Personally, I would have gone with something more along the lines of generic type Value is private; with function ">"(A, B : Value) return Boolean is <>; procedure Homework_Assignment(A, B : in out Value); -- Exchange is defined in the Ada Reference Manual with Exchange; procedure Homework_Assignment(A, B : in out Value) is procedure Swap is new Exchange(Value); begin if A > B then Swap(A,B); end if; end Homework_Assignment; Can't you imagine how pleased the instructor will be to find out that the student has already mastered generics?