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.9 required=5.0 tests=BAYES_00,LOTS_OF_MONEY autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,bccad95d5436eaf8 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!newsread.com!newsprint.newsread.com!news.glorb.com!Spring.edu.tw!news.nctu.edu.tw!feeder.seed.net.tw!netnews!not-for-mail From: "bubble" Newsgroups: comp.lang.ada Subject: Re: Ada begginer's new problem. Date: Fri, 29 Oct 2004 10:58:48 +0800 Organization: HiNetNews Message-ID: References: <2ud2i7F29ahnhU1@uni-berlin.de> NNTP-Posting-Host: 211.21.128.195 X-Trace: netnews.hinet.net 1099019306 18549 211.21.128.195 (29 Oct 2004 03:08:26 GMT) X-Complaints-To: usenet@HiNetnews.hinet.net NNTP-Posting-Date: Fri, 29 Oct 2004 03:08:26 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Xref: g2news1.google.com comp.lang.ada:5815 Date: 2004-10-29T10:58:48+08:00 List-Id: > > In the above construction, it appears execute_some_Statement_here5 can > never be executed. Did you make a mistake? For example, I want print all prime number between 1 to 1000; I rewrite java version prime example to ada version. The code is WITH ada.Text_IO; PROCEDURE primeNum is PACKAGE sout is new ada.Text_IO.Integer_IO(integer); test:integer:=1; begin sout.put(1); ada.Text_IO.New_Line; loop test := test+2; EXIT when test >1000; FOR fac in 2..test-1 loop IF test mod fac =0 THEN goto continueLoop; END IF; end loop; sout.put(test); ada.Text_IO.New_Line; <> null; end loop; end primeNum; now I change it to another version. It seem better. WITH ada.Text_IO; PROCEDURE primeNum is PACKAGE sout is new ada.Text_IO.Integer_IO(integer); test:integer:=1; FUNCTION isPrime(test:integer) return boolean is begin FOR fac in 2..test-1 loop IF test mod fac =0 THEN RETURN false; END IF; end loop; RETURN true; end isPrime; begin sout.put(1); ada.Text_IO.New_Line; loop test := test+2; EXIT when test >1000; IF isPrime(test)=true THEN sout.put(test); ada.Text_IO.New_Line; END IF; end loop; end primeNum; thank jacob,larry,eric,nick, your suggestions are very useful. > Anyway, my personal advice would be not to try to eliminate gotos that > are difficult to eliminate. I think it is nearly always better (clearer, > easier to understand) to leave them in. > > > I know there are some choices can apply to my program. > > ( a ). Type stock_price is new float; > > ( b ). Type stock_price is digits 5; > > ( c ). Subtype stock_price is float; > > ... > > if we don't consider ( c ) style, only consider (a) and (b). > > which style is best? > > I suggest you use a decimal fixed-point type for a stock price. It has > absolute accuracy. For example: > > type Stock_Price_in_Dollars is > delta 0.01 digits 10 range 0.00 .. 99_999_999.99; > > This requests a type which is always accurate to the cent, and can > represent values up to (but not including) $100mil. > > It is usually better to declare types with an explicit request of the > properties you require of them. It may be possible for a pre-existing > type to not have these properties. > > I think it is possible that you might want a more general-purpose type > to do all your currency calculations, and to use subtypes to impose > appropriate ranges. For example: > > type Dollars is delta 0.01 digits 10; > > subtype Stock_Price_in_Dollars is > Dollars range 0.00 .. 99_999_999.99; > > subtype Price_Differential_in_Dollars is > Dollars range -99_999_999.99 .. 99_999_999.99; > > This way, you do not have the (probably inapproprate) inconvenience of > doing a lot of conversions to do mixed arithmetic: > > Old_Price, New_Price: Stock_Price_in_Dollars; > Price_Change: Price_Differential_in_Dollars; > ... > New_Price := Old_Price + Price_Change; > > > 3. possible assign a IEEE754 NaN value to float type variable? > > It is implementation defined how to do this sort of thing. If you look > in the reference manual for your Ada compiler, you may find that there > is a method (for example, an implementation-defined attribute). > > -- > HTH > Nick Roberts