# Does "while" start a new scope now?

**URL:** https://discourse.julialang.org/t/does-while-start-a-new-scope-now/15341
**Category:** General Usage
**Created:** [September 22, 2018, 4:42pm UTC](https://discourse.julialang.org/t/does-while-start-a-new-scope-now/15341 "2018-09-22T16:42:21Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![NKC](https://avatars.discourse-cdn.com/v4/letter/n/258eb7/32.png) [@NKC](https://discourse.julialang.org/u/NKC)
#### Post date: [September 22, 2018, 4:42pm UTC](https://discourse.julialang.org/t/does-while-start-a-new-scope-now/15341/1 "2018-09-22T16:42:21Z")

</div>

Hello,  
Does “while” start a new scope now?  
Below code was not working without global y definition?  
Am I wrong?

```julia
function f3()
        y=0
        while y<5
                y=y+1
                print("f3: y=",y,"\n")        
        end
end

```

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [September 22, 2018, 4:44pm UTC](https://discourse.julialang.org/t/does-while-start-a-new-scope-now/15341/2 "2018-09-22T16:44:26Z")

</div>

Yes [it does](https://docs.julialang.org/en/v1/manual/variables-and-scoping/), but in a function it should still use the one from the containing scope. Which version are you running? The code works for me, but only after fixing your broken `"` in the print statement (notice how they are differing later in the same line).

By the way, you can create code blocks in Discourse by wrapping your code in triple backticks (```).

---

<div class="post-metadata">

### Author: ![NKC](https://avatars.discourse-cdn.com/v4/letter/n/258eb7/32.png) [@NKC](https://discourse.julialang.org/u/NKC)
#### Post date: [September 22, 2018, 4:53pm UTC](https://discourse.julialang.org/t/does-while-start-a-new-scope-now/15341/3 "2018-09-22T16:53:09Z")

</div>

Sorry I couldn’t remember back ticks.

Was it doing after ver 1.0.0 (2018-08-08)? May be I remember wrong…

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [September 22, 2018, 4:55pm UTC](https://discourse.julialang.org/t/does-while-start-a-new-scope-now/15341/4 "2018-09-22T16:55:08Z")

</div>

I’ve just tested it on both 0.7 and 1.0, both worked fine for me.

---

<div class="post-metadata">

### Author: ![NKC](https://avatars.discourse-cdn.com/v4/letter/n/258eb7/32.png) [@NKC](https://discourse.julialang.org/u/NKC)
#### Post date: [September 22, 2018, 4:56pm UTC](https://discourse.julialang.org/t/does-while-start-a-new-scope-now/15341/5 "2018-09-22T16:56:04Z")

</div>

Ok thank you.

This means I need a holiday…
