# Function doesn't show result

**URL:** https://discourse.julialang.org/t/function-doesnt-show-result/38027
**Category:** New to Julia
**Tags:** question, loops, input-output, function
**Created:** [April 22, 2020, 2:15pm UTC](https://discourse.julialang.org/t/function-doesnt-show-result/38027 "2020-04-22T14:15:32Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Jul](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@Jul](https://discourse.julialang.org/u/Jul)
#### Post date: [April 22, 2020, 2:15pm UTC](https://discourse.julialang.org/t/function-doesnt-show-result/38027/1 "2020-04-22T14:15:33Z")

</div>

Hello! I wrote little function but its not show output. I am fresh in this language and I’ve no idea why it’s not work.  
My input is : f(x-\>1) after that program freezes.  
This is function:

```julia
function f(func=x^2)
a_lower = 1 
b_upper = 2  
ro = (3 - sqrt(5))/2
eps = b_upper - a_lower

a_old = a_lower
b_old = b_upper
iter = 0
while(eps > 10^-5)
   
    a_new = a_old + (b_old - a_old)*ro 
    b_new = b_old - (b_old - a_old)*ro
    
    if (func(b_new) > func(a_new))
        b_old = b_new       
    elseif (func(b_new) < func(a_new))
        a_old = a_new
    end
    eps = b_old - a_old
    iter = iter + 1
    
end

print(a_new,func(a_new))

```

---

<div class="post-metadata">

### Author: ![Syx\_Pek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/syx_pek/32/6364_2.png) [@Syx\_Pek](https://discourse.julialang.org/u/Syx_Pek)
#### Post date: [April 22, 2020, 2:34pm UTC](https://discourse.julialang.org/t/function-doesnt-show-result/38027/2 "2020-04-22T14:34:34Z")

</div>

There are two issues with this function.

1. Your function infinite loops as `func(b_new) = 1` and `func(a_new) = 1` so `b_old` and `a_old` will never get updated.

2. You are `print(a_new,func(a_new))` in the last line, but `a_new` is not in scope in here. (I’m assuming there is also an `end` after your whole code)

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [April 22, 2020, 4:47pm UTC](https://discourse.julialang.org/t/function-doesnt-show-result/38027/3 "2020-04-22T16:47:48Z")

</div>

The parameters of `f` seem a little odd to me, what `f(func=x^2)` should mean? It seems to mean that `func` is the sole parameter and it can be ommited, in this case, the value is the square of a global variable `x`?

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [April 23, 2020, 6:32am UTC](https://discourse.julialang.org/t/function-doesnt-show-result/38027/4 "2020-04-23T06:32:00Z")

</div>

Welcome to the Julia forum! There are several problems with your code:

1. the function is missing an `end` (please indent properly, that should help you catch those things)

2. the `func` default argument `x^2` is not a function, but a value (if `x` is in scope), perhaps you meant `x -> x^2` (which is, BTW, available as `abs2` in Julia)

3. finally, for `x -> 1`, neither branch is called (`1 < 1` is always false), so no values are changed. You can print things in a loop (see `@show`), or use the debugger. It may be better to just use an `else` anyway.
