# How to write this Boolean operator?

**URL:** <https://discourse.julialang.org/t/how-to-write-this-boolean-operator/90607>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 21, 2022, 9:09pm UTC](https://discourse.julialang.org/t/how-to-write-this-boolean-operator/90607 "2022-11-21T21:09:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leon6](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leon6/32/205483_2.png) [@Leon6](https://discourse.julialang.org/u/Leon6)\
**Post date:** [November 21, 2022, 9:09pm UTC](https://discourse.julialang.org/t/how-to-write-this-boolean-operator/90607/1 "2022-11-21T21:09:44Z")

</div>

Y is latitude and I want those that are falling within -90 and 90 degrees.

`Indx = Y .> -90 .& Y.< 90;`

I tried &, &&, .&. All of them gave me headaches. What should be the correct way of expressing this in Julia?

Thanks!

---

<div class="post-metadata">

**Author:** ![cchderrick](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@cchderrick](https://discourse.julialang.org/u/cchderrick)\
**Post date:** [November 21, 2022, 9:14pm UTC](https://discourse.julialang.org/t/how-to-write-this-boolean-operator/90607/3 "2022-11-21T21:14:26Z")

</div>

I think you need some parentheses:

```julia
Indx = (Y .> -90) .& (Y.< 90);

```

---

<div class="post-metadata">

**Author:** ![Leon6](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leon6/32/205483_2.png) [@Leon6](https://discourse.julialang.org/u/Leon6)\
**Post date:** [November 21, 2022, 9:15pm UTC](https://discourse.julialang.org/t/how-to-write-this-boolean-operator/90607/4 "2022-11-21T21:15:19Z")

</div>

Many thanks! Yes, with the parenthesis, it has been working.

---

<div class="post-metadata">

**Author:** ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)\
**Post date:** [November 21, 2022, 9:20pm UTC](https://discourse.julialang.org/t/how-to-write-this-boolean-operator/90607/5 "2022-11-21T21:20:55Z")

</div>

If you find it more convenient, Julia permits comparisons in this form as well:  
`Indx = -90 .< Y .< 90`

---

<div class="post-metadata">

**Author:** ![Leon6](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leon6/32/205483_2.png) [@Leon6](https://discourse.julialang.org/u/Leon6)\
**Post date:** [November 21, 2022, 9:32pm UTC](https://discourse.julialang.org/t/how-to-write-this-boolean-operator/90607/6 "2022-11-21T21:32:15Z")

</div>

Wow, it’s great to learn something even simpler. Many thanks for sharing 👍

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [November 21, 2022, 9:33pm UTC](https://discourse.julialang.org/t/how-to-write-this-boolean-operator/90607/7 "2022-11-21T21:33:10Z")

</div>

Although, if you have latitudes that are smaller than -90 or larger than 90 there may be something wrong, no? (unless you selected another range of length 180 for the latitudes but then that would also need some transformations to all the latitudes.

---

<div class="post-metadata">

**Author:** ![Leon6](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leon6/32/205483_2.png) [@Leon6](https://discourse.julialang.org/u/Leon6)\
**Post date:** [November 22, 2022, 2:05pm UTC](https://discourse.julialang.org/t/how-to-write-this-boolean-operator/90607/8 "2022-11-22T14:05:09Z")

</div>

Thanks for the reply.

That’s true. All the latitudes should be between -90 and 90. Here, I just want my indx to include all. I use indx to get the values from some predefined latitude bands. To be consistent, I use the above argument for the global coverage. Or is there a better way to do this?
