# Question on Short Circuit And

**URL:** https://discourse.julialang.org/t/question-on-short-circuit-and/101597
**Category:** General Usage
**Created:** [July 14, 2023, 2:48am UTC](https://discourse.julialang.org/t/question-on-short-circuit-and/101597 "2023-07-14T02:48:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![TI36XPro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ti36xpro/32/33658_2.png) [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)
#### Post date: [July 14, 2023, 2:48am UTC](https://discourse.julialang.org/t/question-on-short-circuit-and/101597/1 "2023-07-14T02:48:36Z")

</div>

I was reviewing some source code recently for a package I am using and saw a function essentially defined like this (dumbed down to a MWE here).

```julia
function func(n)
(n >= 5) && return "yes"
return "no"
end

```

I was very confused when I saw this. It has the same impact as doing

```julia
if n >= 5
    return "yes"
else
    return "no"
end

```

So why not do that? The line `(n >= 5) && return "yes"` is just so much less readable than the `if-else` statement. Perhaps it was done for performance reasons?

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [July 14, 2023, 2:59am UTC](https://discourse.julialang.org/t/question-on-short-circuit-and/101597/2 "2023-07-14T02:59:20Z")

</div>

performance is the same. it’s purely stylistic

---

<div class="post-metadata">

### Author: ![HanD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hand/32/213908_2.png) [@HanD](https://discourse.julialang.org/u/HanD)
#### Post date: [July 14, 2023, 7:55am UTC](https://discourse.julialang.org/t/question-on-short-circuit-and/101597/3 "2023-07-14T07:55:53Z")

</div>

There could be several reasons of for writing code like this. Here’s two:

1. **early return** : It is good practice and idiomatic in many imperative languages to test for the trivial edge cases first, and use early returns in a function body. This technique lets you focus on the real problem.
2. **no else after return** : some linters issue a warning when you have an else branch after a return clause in a then branch. This is reasonable, because the else is, strictly speaking unnecessary, and increases indendation.

Note that both reasons make real sense only when the else branch is a lot more complicated. In this particular case, I’m guessing it’s just a convention/habit that was blindly followed. I personally would write this using a ternary operator:

```julia
return n >= 5 ? "yes" : "no"

```
