# How to define a function using the same loop variable

**URL:** <https://community.wolfram.com/t/how-to-define-a-function-using-the-same-loop-variable/5512>\
**Category:** Questions\
**Tags:** physics\
**Created:** [April 23, 2015, 7:55am UTC](https://community.wolfram.com/t/how-to-define-a-function-using-the-same-loop-variable/5512 "2015-04-23T07:55:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![soumyakantibose09](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/soumyakantibose09/32/4309_2.png) [@soumyakantibose09](https://community.wolfram.com/u/soumyakantibose09)\
**Post date:** [April 23, 2015, 7:55am UTC](https://community.wolfram.com/t/how-to-define-a-function-using-the-same-loop-variable/5512/1 "2015-04-23T07:55:36Z")

</div>

I was running this code and got the result as follows,

For[zr = 0.10, zr \<= 0.50, zr = zr + 0.10,  
zx = Tanh[zr]  
Print[{zr, zx}]]

{0.1,0.781806 Null}

{0.2,0.099668 Null}

{0.3,0.197375 Null}

{0.4,0.291313 Null}

{0.5,0.379949 Null}  
Please tell me the solution.

---

<div class="post-metadata">

**Author:** ![mthiel](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mthiel/32/42877_2.png) [@mthiel](https://community.wolfram.com/u/mthiel)\
**Post date:** [April 23, 2015, 12:41pm UTC](https://community.wolfram.com/t/how-to-define-a-function-using-the-same-loop-variable/5512/2 "2015-04-23T12:41:29Z")

</div>

Hi,

I do not fully understand what you want to achieve, but I guess that there is at least one semi-colon missing:

```
For[zr = 0.10, zr <= 0.50, zr = zr + 0.10, zx = Tanh[zr]; Print[{zr, zx}]]

```

which gives:

```
{0.1,0.099668}
{0.2,0.197375}
{0.3,0.291313}
{0.4,0.379949}
{0.5,0.462117}

```

Cheers,

Marco

---

<div class="post-metadata">

**Author:** ![soumyakantibose09](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/soumyakantibose09/32/4309_2.png) [@soumyakantibose09](https://community.wolfram.com/u/soumyakantibose09)\
**Post date:** [April 23, 2015, 5:56pm UTC](https://community.wolfram.com/t/how-to-define-a-function-using-the-same-loop-variable/5512/3 "2015-04-23T17:56:04Z")

</div>

Thanks a lot to you Marco. It has solved my problem.
