# Structure not created but no error reported

**URL:** https://discourse.julialang.org/t/structure-not-created-but-no-error-reported/93354
**Category:** New to Julia
**Tags:** question
**Created:** [January 22, 2023, 11:02am UTC](https://discourse.julialang.org/t/structure-not-created-but-no-error-reported/93354 "2023-01-22T11:02:47Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Bananthahally](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bananthahally/32/222983_2.png) [@Bananthahally](https://discourse.julialang.org/u/Bananthahally)
#### Post date: [January 22, 2023, 11:02am UTC](https://discourse.julialang.org/t/structure-not-created-but-no-error-reported/93354/1 "2023-01-22T11:02:47Z")

</div>

Hi folks  
I’m not able to get the following to yield the structure for the instance `Tst` described in the REPL further below. No error however is reported by Julia.

```julia
mutable struct CvDv_ForAll_Voids
    CvDv_Trapz :: Array{Float64,2}
    CvDv_Trian :: Array{Float64,2}

    function CvDv_ForAll_Voids(CvDv_Trapz, CvDv_Trian, NTrapz, NTrian)
        Case1 = (NTrapz != 0) & (NTrian != 0)
        Case2 = (NTrapz != 0) & (NTrian == 0)
        Case3 = (NTrapz == 0) & (NTrian != 0)
        Case4 = (NTrapz == 0) & (NTrian == 0)
        if Case1==1 new(CvDv_Trapz,CvDv_Trian); end
        if Case2==1 new(CvDv_Trapz,zeros(1,2)); end
        if Case3==1 new(zeros(1,2),CvDv_Trian); end
        if Case4==1 new(zeros(1,2),zeros(1,2)); end
    end
end

```

Inside the REPL, this is what I created and asked in order to form a strucure called `Tst`:

```julia

julia> A :: Array{Float64,2} = fill(0.75, (4,2))
4×2 Matrix{Float64}:
 0.75 0.75
 0.75 0.75
 0.75 0.75
 0.75 0.75

julia> B :: Array{Float64,2} = fill(0.15, (3,2))
3×2 Matrix{Float64}:
 0.15 0.15
 0.15 0.15
 0.15 0.15

julia> Tst = CvDv_ForAll_Voids(A,B,1,1)

julia> 
julia> Tst

julia> typeof(Tst)
Nothing

```

I ran the above using the Debugger on VS Code and **did see** that `Case1` was `true` while `Case2`, `Case3` and `Case 4` were all `false`. So still why didn’t the inner constructor function return `Nothing` rather than create the structure fields using the contents of `A` and `B`?

Thanks in advance.

---

<div class="post-metadata">

### Author: ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)
#### Post date: [January 22, 2023, 11:13am UTC](https://discourse.julialang.org/t/structure-not-created-but-no-error-reported/93354/2 "2023-01-22T11:13:37Z")

</div>

The first conditional executes and successfully constructs a new object and returns it.

But then the remaining three conditionals execute, and they all return `nothing`.

Most importantly, the final conditional returns `nothing`, and that is then the return value of your inner constructor.

Consider either:

a) using `return` statements  
b) using mutually exclusive conditions with `elseif`

Note that you don’t need to compare `true` against `true`; you can simply test `if Case1`. Also, for boolean comparisons it is usually more convenient to use `&&`, which has lower precedence so the equality comparisons don’t need to be parenthesized.

---

<div class="post-metadata">

### Author: ![Bananthahally](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bananthahally/32/222983_2.png) [@Bananthahally](https://discourse.julialang.org/u/Bananthahally)
#### Post date: [January 22, 2023, 11:30am UTC](https://discourse.julialang.org/t/structure-not-created-but-no-error-reported/93354/3 "2023-01-22T11:30:28Z")

</div>

The conditionals for Case2, Case3 and Case4 should NOT execute because they’re false and NOT satisfied to create the new(…) under them.

Isn’t this how it’s supposed to be ?

---

<div class="post-metadata">

### Author: ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)
#### Post date: [January 22, 2023, 11:36am UTC](https://discourse.julialang.org/t/structure-not-created-but-no-error-reported/93354/4 "2023-01-22T11:36:44Z")

</div>

Sorry, I misspoke.

The remaining three conditionals evaluate their conditions, which are `false`. When that occurs, they do not evaluate the code in their body, and return `nothing`.

The point stands though, that you either need to use `return` to terminate the function early, or use mutually exclusive conditionals. Otherwise the last conditional’s return value of `nothing` becomes the function’s return value.

---

<div class="post-metadata">

### Author: ![Bananthahally](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bananthahally/32/222983_2.png) [@Bananthahally](https://discourse.julialang.org/u/Bananthahally)
#### Post date: [January 22, 2023, 3:49pm UTC](https://discourse.julialang.org/t/structure-not-created-but-no-error-reported/93354/5 "2023-01-22T15:49:01Z")

</div>

Thanks, @uniment

I’ll try preceding the new(…) with return and update asap. Also noted your other suggestions.
