On Thu, 11 Sep 2014, reinkor wrote: > k := i1 + i2; -- store "i1 + i2" in k to avoid recalculation (?) > loop > for i in k .. n loop > Do something... > end loop; > end loop; > loop > for i in i1 + i2 .. n loop -- will recalculate "i1 + i2" ? > Do something... > end loop; > end loop; > > What is the "best" alternative? I assume you turn on the compiler's optimisation setting. I didn't try it, but I would expect the following: - If "Do something" is sufficiently simple, the Ada compiler will find out that i1, i2 and, for the first variant, k, don't change. Then the generated code should be the same. - If "Do something" is so complex that the Ada compiler is unable to find out that neither of i1, i2, and k change, you are unlikely to notice any difference in speed, since the time to compute i1+i2 is will be negligible, compared to the time for "Do something". Nevertheless, if you want to make sure the compiler notices that neither i1 nor i2 change, you could declare them as constants: declare I1: constant Some_Type := Get_I1; I2: constant Some_Type := Get_I2; begin loop for I in I1+I2 .. N loop Do_Something end loop; end loop; end; ------ I love the taste of Cryptanalysis in the morning! ------ --Stefan.Lucks (at) uni-weimar.de, Bauhaus-Universität Weimar, Germany--