On Mon, 13 Aug 2018, Riccardo (Jack) Lucchetti wrote:
On Mon, 13 Aug 2018, Allin Cottrell wrote:
> You can create such a "backwards" loop at present, either using the more
> flexible (but more cumbersome) "for" construct or by adding an auxiliary
> index, but it would be convenient to have the decrement case handled
> automatically.
Sorry to point out the obvious, but in many cases you don't need a for loop
at all, just a temporary variable, as in
loop i = 1 .. n
j = n - i + 1
[ ... whatever ... ]
endloop
That's an example of what I meant by an "auxiliary index".
On the other hand, I don't think a double loop like
loop i = 1 .. n
loop j = i+1 .. n
...
endloop
endloop
should be considered buggy code: you may legitimately want to process the
lower triangle of a matrix, for example.
It's not exactly buggy if the coder is relying on the documented
behavior of gretl's index loop. But the inner loop will reach
j = n+1..n, which is a problem for an n x n matrix unless it's
blocked. To process the lower triangle you'd want something like
loop i=1..n
loop j=1..i
Given the potential for breakage, I'm not a great fan of the
--decrement option, especially considering that the alternative is
relatively painless in all the examples I can think of. Maybe I'm
missing something?
Probably not (missing anything). If we're OK with the status quo
that's fine by me.
Allin