I am trying to run over an structure of data (slice), and inside the loop I need to check a little thing. For this purpose I use a variable that is set up before the loop, but if a condition is met, this variable must change the value. Ok!! Inside the loop I print the variable and I see how it changes the value... BUT in each iteration of the loop the variable restarts and get the initial value again.
This is my code:
{{range $response := .result}}
{{$old := "FALSE"}}
{{range $seat := $response.SeatList}}
{{$old}} -------
{{if ne $old $seat.Row}} {{$old := $seat.Row}} {{$old}} ------- {{end}}
{{end}}
{{end}}
And it prints something like:
FALSE ------- 4 -------
FALSE ------- 4 -------
FALSE ------- 5 -------
FALSE ------- 5 -------
FALSE ------- 6 -------
FALSE ------- 6 -------
When it should print something like:
FALSE ------- 4 -------
4 -------
4 ------- 5 -------
5 -------
5 ------- 6 -------
6 -------
I tried too to make {{$old = $seat.Row}}
without colon... but I get a sintaxis error unexpected "=" in operand
.
Any way to don't restart teh value of the variable?? Thank you.
PS: I am using revel framework.