# Will my variable be modified in a \`do\` block? Very subtle to anticipate

**URL:** <https://discourse.julialang.org/t/will-my-variable-be-modified-in-a-do-block-very-subtle-to-anticipate/131124>\
**Category:** General Usage\
**Tags:** question, threads\
**Created:** [July 28, 2025, 6:25am UTC](https://discourse.julialang.org/t/will-my-variable-be-modified-in-a-do-block-very-subtle-to-anticipate/131124 "2025-07-28T06:25:02Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Post date:** [July 28, 2025, 11:04am UTC](https://discourse.julialang.org/t/will-my-variable-be-modified-in-a-do-block-very-subtle-to-anticipate/131124/12 "2025-07-28T11:04:21Z")

</div>

> [@sgaure](#):
>
> In the example with the `my_dumb_fun`, the do-block is never executed.

So you make judgements with the source code of my `my_dumb_fun`. This is to say, the scope inference about the `do` block is much more difficult. (I am not aware what the source code of the `Threads.lock` function is).

Therefore, if the circumstance is like this, I cannot make a deterministic inference

```julia
julia> function modify_a_randomly(af)                                                                                        
           rand() > .5 && return                                                                                             
           af()                                                                                                              
       end;

julia> for i = 1:5
           a = -10i
           modify_a_randomly() do
               a = 10i
           end
           println("i = $i, a = $a")
       end
i = 1, a = 10
i = 2, a = -20
i = 3, a = 30
i = 4, a = -40
i = 5, a = 50

```

---

_[View the full topic](https://discourse.julialang.org/t/will-my-variable-be-modified-in-a-do-block-very-subtle-to-anticipate/131124)._
