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!fu-berlin.de!uni-berlin.de!not-for-mail From: Nick Roberts Newsgroups: comp.lang.ada Subject: Re: Ada begginer's new problem. Date: Thu, 28 Oct 2004 21:19:18 +0100 Message-ID: <2ud2i7F29ahnhU1@uni-berlin.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de GiTqIboZW95UZTTzMXsoDA/sjAHoW9QTf0zZ52TvhKp6jBWss= User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040803 X-Accept-Language: en-us, en In-Reply-To: Xref: g2news1.google.com comp.lang.ada:5806 Date: 2004-10-28T21:19:18+01:00 List-Id: bubble wrote: > outer:loop > execute_some_Statement_here0; > EXIT when some_condition; > execute_some_Statement_here1; > inner: loop > execute_some_Statement_here3; > IF some_condition_is_true THEN > goto outerContinueLabel; > END IF; > execute_some_Statement_here4; > end loop inner; > execute_some_Statement_here5; > <> > null; > end loop outer; > > It's hard to read, > How should I do to remove "goto" ....? In the above construction, it appears execute_some_Statement_here5 can never be executed. Did you make a mistake? 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