Re: Proposal : For-Loop Iteration for Real Type "Jackson, Justin" <[log in to unmask]> Fri, 31 Aug 2001 12:50:34 +0100 text/plain (80 lines) ``` Toshitaka KUMANO <[log in to unmask]> wrote > This is a proposal of extension to Ada, about > loop_parameter_specification. > > Any comments ? > Having used real type loop counter in other languages and found them useful, I support the idea. I suggest that the safest basis for such a count is a decimal type, since this minimises uncertainty about the delta and hence the loop step size. Floating point loop counters were used in some basics but these were for less critical purposes than a typical Ada application. While we are revisiting the for loop, perhaps we could think about increasing its flexibility to match other languages, most notably by allowing a step size to be specified: this would apply to discrete loop counter types as well as real ones. In Coral66 we had for loops with integer counters, such as FOR i:=start_value STEP step_size UNTIL stop_value and also the form FOR i:=value1,value2,value3 etc DO (The values were numeric expressions and I believe dynamically evaluated, so not necessarily in ascending order) [Caveat: memory a little vague & no Coral manual to hand!] ..and in some basics on the old 80's micros you could have, for example, FOR n=2*PI TO 0 STEP -2*PI/360 where n was floating point - some basics which supported integers nevertheless insisted on loop counters being floating point. Rather than introduce another Ada keyword, "delta" could be overloaded in the loop construct to do the job of STEP. In the absence of delta usage in the loop construct, the step would default to 'Succ - which for real loop counters would be the delta of the decimal type or subtype of the loop counter. So the Ada XX for the specimen line of Coral would be for I in start_value..stop_value delta step_size loop e.g. for I in 1..12 delta 2 loop would iterate through values 1,3,5,7,9,11 while for I in 0..12 delta 2 loop would iterate through values 0,2,4,6,8,10,12 Meanwhile the AdaXX for that line of basic would be    for Theta in reverse 0.0..2.0*PI delta 2.0*PI/360.0 loop It is highly desirable that any mumeric expression for step size is an exact multiple of the delta of the decimal loop counter type: obviously the step size is of the same type as the loop counter. Should the step size be static? If not should step size modification be permitted within the body of the loop? Any interest in the value-list iteration scheme as in the second Coral example? Discuss! The behaviour of such constructs should be easy to simulate in Ada9X with a generic subprogram instantiated for the loop counter type and reading as parameters the loop start, stop and step values.   Regards       Justin Jackson ------------------------------ Justin Jackson BAE SYSTEMS New Malden Surrey UK ******************************************************************** This email and any attachments are confidential to the intended recipient and may also be privileged. If you are not the intended recipient please delete it from your system and notify the sender. You should not copy it or use it for any purpose nor disclose or distribute its contents to any other person. ******************************************************************** ```