0

Is it possible to compare the value of the current and the previous iteration in a for loop in Acceleo?

Knowing that LET can be defined inside for loop but it will be mutable at each current iteration, therefore the previous value will be lost and we will get always only the current value.

Lii
  • 11,553
  • 8
  • 64
  • 88
Geek
  • 189
  • 3
  • 13

1 Answers1

2

In for loops in acceleo you have access to a variable i:

[let seq : Sequence(Integer) = Sequence{4,5,6}]
    [for (n : Integer | seq)]
        [seq->at(i-1)/]
    [/for]
[/let]

Outputs:

Invalid
4
5

Beware of edge cases such as the first and last items.

Here you can find some extremely helpful documentation

Andrés Esguerra
  • 849
  • 5
  • 15