# Shortcut if isnothing(variable = match(...))

**URL:** <https://discourse.julialang.org/t/shortcut-if-isnothing-variable-match/85390>\
**Category:** New to Julia\
**Created:** [August 6, 2022, 10:33am UTC](https://discourse.julialang.org/t/shortcut-if-isnothing-variable-match/85390 "2022-08-06T10:33:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![whatsthecraic](https://avatars.discourse-cdn.com/v4/letter/w/7bcc69/32.png) [@whatsthecraic](https://discourse.julialang.org/u/whatsthecraic)\
**Post date:** [August 6, 2022, 10:33am UTC](https://discourse.julialang.org/t/shortcut-if-isnothing-variable-match/85390/1 "2022-08-06T10:33:45Z")

</div>

Hi all,  
does it exist a shorter syntax to write some like this:

```julia
elseif !isnothing(m = match(...)
   .. use m

```

rather than the more verbose and nested block:

```julia
else 
  m = match(...)
  if !isnothing(m)
    .. use m
  end
end

```

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [August 6, 2022, 12:12pm UTC](https://discourse.julialang.org/t/shortcut-if-isnothing-variable-match/85390/2 "2022-08-06T12:12:29Z")

</div>

You are looking for `something`. See `? something` for details.

Since 1.7 there is also a macro `@something` which makes slightly easier syntax (and is also faster, since it short-circuits)

```julia
julia> x = "hello";

julia> match(r"zz", x)

julia> @something match(r"zz", x) "tt"
"tt"

```

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [August 6, 2022, 12:56pm UTC](https://discourse.julialang.org/t/shortcut-if-isnothing-variable-match/85390/3 "2022-08-06T12:56:15Z")

</div>

I usually use this style:

```julia
elseif (m = match(...); m !== nothing)
    # use m...
end

```

---

<div class="post-metadata">

**Author:** ![ikirill](https://avatars.discourse-cdn.com/v4/letter/i/43a26b/32.png) [@ikirill](https://discourse.julialang.org/u/ikirill)\
**Post date:** [August 6, 2022, 4:04pm UTC](https://discourse.julialang.org/t/shortcut-if-isnothing-variable-match/85390/4 "2022-08-06T16:04:23Z")

</div>

You can just use

```julia
x = 1
if (y = x) !== nothing
 @show y
end

```

The difference is that `!==` is not a function call, so it doesn’t get parsed as an argument to a function, but just an assignment to a variable in the scope of if.
