# Setting a default variable?

**URL:** <https://discourse.julialang.org/t/setting-a-default-variable/23867>\
**Category:** New to Julia\
**Created:** [May 5, 2019, 1:19pm UTC](https://discourse.julialang.org/t/setting-a-default-variable/23867 "2019-05-05T13:19:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [May 5, 2019, 1:19pm UTC](https://discourse.julialang.org/t/setting-a-default-variable/23867/1 "2019-05-05T13:19:04Z")

</div>

Hey guys

Basically I have loop which looks like this:

```julia
function readVtkVariables(filename::String,reset::Bool)
        k::Array{String} = []
        #Open the specific file
        fd::IOStream = open(filename, read=true)
        for i in instances(Cat)
            #Read until the specific enum string has been found. Ie. Mk => "Mk " etc.
            if reset == true
                seek(fd,0)
            else
            end
            readuntil(fd, searchString[i])
            k = push!(k,string(i))
        end
        return k
    end

```

What I would like to do is to set the “reset” input as false always, unless otherwise stated. So basically I want the user to be able to write, this which would be the same thing:

```julia
readVtkVariables("PartSquare_0000.vtk")
readVtkVariables("PartSquare_0000.vtk",false)

```

I know I could do multiple dispatch, but I think that shouldn’t be necessary for this short code.

Kind regards

---

<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:** [May 5, 2019, 1:22pm UTC](https://discourse.julialang.org/t/setting-a-default-variable/23867/2 "2019-05-05T13:22:53Z")

</div>

> [@Ahmed\_Salih](#):
>
> function readVtkVariables(filename::String,reset::Bool)

```julia
function readVtkVariables(filename::String,reset::Bool = false)

```

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [May 5, 2019, 1:25pm UTC](https://discourse.julialang.org/t/setting-a-default-variable/23867/3 "2019-05-05T13:25:00Z")

</div>

Thanks! Much better than Matlab’s nargin in my opinion, so I am a happy man 🙂

---

<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:** [May 5, 2019, 1:37pm UTC](https://discourse.julialang.org/t/setting-a-default-variable/23867/4 "2019-05-05T13:37:46Z")

</div>

Continued future happiness can be ensured by reading the manual, eg

[https://docs.julialang.org/en/v1/manual/functions/](https://docs.julialang.org/en/v1/manual/functions/)

😉

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [May 5, 2019, 1:39pm UTC](https://discourse.julialang.org/t/setting-a-default-variable/23867/5 "2019-05-05T13:39:25Z")

</div>

Haha, you are of course right. Often times I try doing a quick google search and seeing if anything comes up - then it is nice for us not so tech-savvy people with a forum, with a lot of helpful heads 🙂
