Is there a way to access the previous iteration result/returned value in a loop?

Because, I am trying to build an expression rule which when supplied with two integer inputs (say 3 and 5), should return me {{1,2,3},{4,5,6},{7,8,9},{10,11,12},{13,14,15}}(An array of arrays).

If I pass 2 and 4, it should return me {{1,2},{3,4},{5,6},{7,8}}.

  Discussion posts and replies are publicly visible

Parents
  • I wouldn't be surprised if your actual use case is more complex, but here's an expression that gives the result you were asking for:

    = a!foreach(
    items: 1+enumerate(ri!arrayCount),
    expression: with(
    local!idx: fv!item,
    a!foreach(
    items: 1+enumerate(ri!subarrayCount),
    expression: fv!item + ri!subarrayCount * (local!idx - 1)
    )
    )
    )

    Having arrayCount=5 and subarrayCount=3, the result is: {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}, {13, 14, 15}}

Reply
  • I wouldn't be surprised if your actual use case is more complex, but here's an expression that gives the result you were asking for:

    = a!foreach(
    items: 1+enumerate(ri!arrayCount),
    expression: with(
    local!idx: fv!item,
    a!foreach(
    items: 1+enumerate(ri!subarrayCount),
    expression: fv!item + ri!subarrayCount * (local!idx - 1)
    )
    )
    )

    Having arrayCount=5 and subarrayCount=3, the result is: {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}, {13, 14, 15}}

Children