# Running a code for multiple values of the same variable

**URL:** https://discourse.julialang.org/t/running-a-code-for-multiple-values-of-the-same-variable/43843
**Category:** General Usage
**Created:** [July 28, 2020, 10:07pm UTC](https://discourse.julialang.org/t/running-a-code-for-multiple-values-of-the-same-variable/43843 "2020-07-28T22:07:09Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![marouane1994](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marouane1994](https://discourse.julialang.org/u/marouane1994)
#### Post date: [July 28, 2020, 10:07pm UTC](https://discourse.julialang.org/t/running-a-code-for-multiple-values-of-the-same-variable/43843/1 "2020-07-28T22:07:09Z")

</div>

I wanna know if there is a simple way to run a code containing a variable `x` that should take more than one value and then store these values with the outputs of the code, for example `x` takes more than one value like 1 and 2 and 3, how can i run the code directly for once with all these values without changing the value of `x` everytime also how can i save the each output of each value of `x`

---

<div class="post-metadata">

### Author: ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)
#### Post date: [July 28, 2020, 10:22pm UTC](https://discourse.julialang.org/t/running-a-code-for-multiple-values-of-the-same-variable/43843/2 "2020-07-28T22:22:33Z")

</div>

Use the dot notation for broadcasting.

```julia
x = [1, 2, 3]
y = log.(x)

```

---

<div class="post-metadata">

### Author: ![marouane1994](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marouane1994](https://discourse.julialang.org/u/marouane1994)
#### Post date: [July 29, 2020, 11:29am UTC](https://discourse.julialang.org/t/running-a-code-for-multiple-values-of-the-same-variable/43843/3 "2020-07-29T11:29:28Z")

</div>

what if:

```julia
x=1
y=fill(sqrt(x),3)
z=tanh.(y)

```

and i want to do the same for `x=[1,2,3]`

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [July 29, 2020, 11:33am UTC](https://discourse.julialang.org/t/running-a-code-for-multiple-values-of-the-same-variable/43843/4 "2020-07-29T11:33:25Z")

</div>

This is more or less exactly what  
[https://github.com/baggepinnen/MonteCarloMeasurements.jl](https://github.com/baggepinnen/MonteCarloMeasurements.jl)  
is made for. It’s framed as a way of propagating probability distributions through nonlinear functions, but the way it does it is exactly what you are asking for, by propagating several samples from the distribution.

---

<div class="post-metadata">

### Author: ![marouane1994](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marouane1994](https://discourse.julialang.org/u/marouane1994)
#### Post date: [July 30, 2020, 9:35am UTC](https://discourse.julialang.org/t/running-a-code-for-multiple-values-of-the-same-variable/43843/5 "2020-07-30T09:35:28Z")

</div>

nice i will take a look at it and try to adapt it with my code, thanks a lot
