loop through table read from / write to cells

I have a table that looks like this:

style option duration prevStyle prevOption
0 0 20    
1 0 24    
0 0 40    
13 1 70    
0 0 10    

I'm trying to create a workflow that loops through this table and 'remembers' the last style / option value where the style was greater than 0. If a row with duration greater than 60 is encountered then the style / option in memory should be written in the columns prevStyle / prevOption to arrive at below result

style option duration prevStyle prevOption
0 0 20    
1 0 24    
0 0 40    
13 1 70 1 0
0 0 10    

Essentially the loop should work as follows

Row 1: nothing happens

Row 2: since style > 0: style = 1 and option = 0 should be remembered

Row 3: nothing happens

Row 4: since duration > 60: the remembered style = 1 and option = 0 is written in the columns prevStyle / prevOption

            since style > 0: style = 13 and option = 1 should be remembered

Row 5: nothing happens ...

In Excel I would solve this problem like that:

  Row = 2
  While Cells(Row, 1) <> ""
    If Cells(Row, 3) > 60 Then
      Cells(Row, 4) = oldStyle
      Cells(Row, 5) = oldOption
    End If
    If Cells(Row, 1) > 0 Then
      oldStyle = Cells(Row, 1)
      oldOption = Cells(Row, 2)
    End If
    Row = Row + 1

I understand that I can loop through the row with a 'table row to variable loop start'. But how can I remember the style and option value of the current iteration if the style is greater than 0? I thought I can create two additional flow variables for that but it seems that the flow variables get set to default for every iteration of my loop. Normally I would use an IF but I cannot figure out how to use any of the IF switches for my purpose. The same holds true for checking the duration value and writing the flow variables back into the table.

Your help would be highly appreciated.


Meanwhile I came up with the attached workflow using 'chunk loop' and 'java snippet'. The above described Excel code I translated into Java to modify two flow variables 'oStyle' and 'oOption'. If I monitor those two variables for the 'java snippet' they include the expected values if the style is greater than 0. However if I monitor the same variables for the 'loop end' node they are still shown with the default value. Needless to say it doesn't work. I have no idea where I'm going wrong.

For the time being I save the flow variables 'oStyle' and 'oOption' to the disc and read them during each loop iteration. Not very elegant but it works. Still would appreciate some feedback on how to do this correctly.