# When should I use broadcasting in Julia instead of a loop?

**URL:** <https://discourse.julialang.org/t/when-should-i-use-broadcasting-in-julia-instead-of-a-loop/139928>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [October 10, 2026, 7:42am UTC](https://discourse.julialang.org/t/when-should-i-use-broadcasting-in-julia-instead-of-a-loop/139928 "2026-10-10T07:42:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ally\_garcia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ally_garcia/32/224560_2.png) [@Ally\_garcia](https://discourse.julialang.org/u/Ally_garcia)\
**Post date:** [October 10, 2026, 7:42am UTC](https://discourse.julialang.org/t/when-should-i-use-broadcasting-in-julia-instead-of-a-loop/139928/1 "2026-10-10T07:42:54Z")

</div>

I’m still getting used to Julia’s broadcasting syntax, especially the use of `.` with functions and operators.

For simple cases, something like:

```julia-auto
y = sin.(x) .+ 1

```

is very convenient.

But once the expression gets a little more complicated, I sometimes find an explicit loop easier to read.

So I’m wondering: in normal Julia code, when do you personally prefer broadcasting, and when would you switch to a loop?

Is this mostly a readability choice, or are there performance differences I should keep in mind as well?

I’m mainly trying to build good habits early rather than automatically adding dots everywhere.

---

<div class="post-metadata">

**Author:** ![yolhan\_mannes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yolhan_mannes/32/220485_2.png) [@yolhan\_mannes](https://discourse.julialang.org/u/yolhan_mannes)\
**Post date:** [October 10, 2026, 7:47am UTC](https://discourse.julialang.org/t/when-should-i-use-broadcasting-in-julia-instead-of-a-loop/139928/2 "2026-10-10T07:47:25Z")

</div>

I only use broadcasting when its single line if its 2 line I just make the loop to fuse them. I don’t know if its the right thing to do but for micro optim I always endup doing it.

---

<div class="post-metadata">

**Author:** ![mahmah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mahmah/32/214326_2.png) [@mahmah](https://discourse.julialang.org/u/mahmah)\
**Post date:** [October 10, 2026, 8:28am UTC](https://discourse.julialang.org/t/when-should-i-use-broadcasting-in-julia-instead-of-a-loop/139928/3 "2026-10-10T08:28:34Z")

</div>

Welcome to the community! Note that you can use @. in this case:

```julia
y = @. sin(x) + 1

```

I love wrapping stuff into functions and then calling them with the dot. It’s very satisfying to do this 🙂
