# Problem updating a variable in a loop

**URL:** <https://forum.elixirforum.com/t/problem-updating-a-variable-in-a-loop/51195>\
**Category:** Questions\
**Tags:** opencv, evision\
**Created:** [October 20, 2022, 7:01am UTC](https://forum.elixirforum.com/t/problem-updating-a-variable-in-a-loop/51195 "2022-10-20T07:01:34Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Gupta](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/ad7895/32.png) [@Gupta](https://forum.elixirforum.com/u/Gupta)\
**Post date:** [October 20, 2022, 7:40am UTC](https://forum.elixirforum.com/t/problem-updating-a-variable-in-a-loop/51195/3 "2022-10-20T07:40:05Z")

</div>

can u explain me briefly what u have done in this

```elixir
square = for contour <- contours, reduce: 0 do
  acc ->
    {:ok,peri} = OpenCV.arcLength(contour,true)
    {:ok,approx} = OpenCV.approxPolyDP(contour, 0.01 * peri,true)
    ap=OpenCV.Nx.to_nx(approx)
    {len,_,_}=Nx.shape(ap)

    if len==4 do #to bound squares from the countor
      {:ok,{x1, y1, w, h}}= OpenCV.boundingRect(approx)
      aspectRatio = (w/1)/h
      if aspectRatio >= 0.95 and aspectRatio <= 1.05 and (y1+h)*(x1+w) < 985000 do
        acc + 1
      else
        acc
      end
    end
end

```

so that in further code if i will face problem regarding this i can rectify it

---

_[View the full topic](https://forum.elixirforum.com/t/problem-updating-a-variable-in-a-loop/51195)._
