# Should throw ERROR when if false?

**URL:** https://discourse.julialang.org/t/should-throw-error-when-if-false/130401
**Category:** General Usage
**Created:** [July 2, 2025, 7:04am UTC](https://discourse.julialang.org/t/should-throw-error-when-if-false/130401 "2025-07-02T07:04:35Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)
#### Post date: [July 2, 2025, 7:04am UTC](https://discourse.julialang.org/t/should-throw-error-when-if-false/130401/1 "2025-07-02T07:04:35Z")

</div>

```julia
julia> if false
           break
       end
ERROR: syntax: break or continue outside loop
Stacktrace:
 [1] top-level scope
   @ REPL[1]:1

```

I think this ERROR doesn’t have to be seen at REPL—it is distracting.

When the condition is false, we don’t actually care about the body of the `if`.  
It should have no difference to the following—which has no ERROR

```julia
julia> quote
           break
       end
quote
    #= REPL[2]:2 =#
    break
end

```

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [July 2, 2025, 7:27am UTC](https://discourse.julialang.org/t/should-throw-error-when-if-false/130401/2 "2025-07-02T07:27:41Z")

</div>

Difference there is the code inside `quote` isn’t being evaluated…yet. If you do, you get the same error.

```julia
julia> eval(quote break end)
ERROR: syntax: break or continue outside loop

```

Evaluation of invalid Julia syntax throwing a syntax error is a lot better than mistakes silently doing something different from what the writer thought was possible.

> [@WalterMadelim](#):
>
> When the condition is false, we don’t actually care about the body of the `if`.

We should. The condition being sometimes true in practice makes that obvious, but even if it were strictly `if false`, the variables in the body are involved in lexical scoping for consistency. A conditional branch that never executes doesn’t make dead code that can be trivially eliminated, and that’s true across many languages. Sometimes we have to just omit code we don’t need.
