# Implementation of AND with the if statement

**URL:** <https://discourse.julialang.org/t/implementation-of-and-with-the-if-statement/121777>\
**Category:** General Usage\
**Created:** [October 26, 2024, 7:54am UTC](https://discourse.julialang.org/t/implementation-of-and-with-the-if-statement/121777 "2024-10-26T07:54:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hack3rcon](https://avatars.discourse-cdn.com/v4/letter/h/96bed5/32.png) [@hack3rcon](https://discourse.julialang.org/u/hack3rcon)\
**Post date:** [October 26, 2024, 7:54am UTC](https://discourse.julialang.org/t/implementation-of-and-with-the-if-statement/121777/1 "2024-10-26T07:54:52Z")

</div>

Hello,  
I want to implement `(h >= 1) && (h <= 99)` with an if statement. Is it possible?

Thank you.

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [October 26, 2024, 8:12am UTC](https://discourse.julialang.org/t/implementation-of-and-with-the-if-statement/121777/2 "2024-10-26T08:12:40Z")

</div>

Yes, of course. I guess you don’t want me to spoil it for you?

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [October 27, 2024, 4:55am UTC](https://discourse.julialang.org/t/implementation-of-and-with-the-if-statement/121777/3 "2024-10-27T04:55:08Z")

</div>

I suggest you review the relevant section in the manual and when you encounter problem reaching your goal then you come back here and try to be as specific as possible about what you tried and what didn’t work 🙂

> **[Control Flow · The Julia Language](https://docs.julialang.org/en/v1/manual/control-flow/#man-conditional-evaluation)**
>
> Documentation for The Julia Language.

---

<div class="post-metadata">

**Author:** ![hack3rcon](https://avatars.discourse-cdn.com/v4/letter/h/96bed5/32.png) [@hack3rcon](https://discourse.julialang.org/u/hack3rcon)\
**Post date:** [October 27, 2024, 9:17am UTC](https://discourse.julialang.org/t/implementation-of-and-with-the-if-statement/121777/4 "2024-10-27T09:17:26Z")

</div>

Hi,  
Thank you so much.

```julia
print("Please enter a number: ")
a=parse(Int,readline())
if (a>=1)
    if (a<=99)
        print("OK")
    end
end

```

Does this make sense in terms of programming?

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [October 27, 2024, 9:56am UTC](https://discourse.julialang.org/t/implementation-of-and-with-the-if-statement/121777/5 "2024-10-27T09:56:55Z")

</div>

Yes.

Perhaps a bit nicer to read is to combine the conditions:

```julia
print("Please enter a number: ")
a=parse(Int,readline())
if (a>=1) && (a<=99)
    print("OK")
end

```

Also note that you don’t need the parenthesis for the condition of the `if`. For more complex conditions (like in my code), the parenthesis can help increase legibility but for very simple conditions (your code) one typically would omit them:

```julia
print("Please enter a number: ")
a=parse(Int,readline())
if a >= 1
    if a <= 99
        print("OK")
    end
end

```

Finally, for this specific example there are alternative ways of writing the condition (not better by any means I am just showing you some more of the language):

```julia
variant1 = a in 1:99
variant2 = 1 <= a <= 99

```

---

<div class="post-metadata">

**Author:** ![hack3rcon](https://avatars.discourse-cdn.com/v4/letter/h/96bed5/32.png) [@hack3rcon](https://discourse.julialang.org/u/hack3rcon)\
**Post date:** [October 30, 2024, 6:22am UTC](https://discourse.julialang.org/t/implementation-of-and-with-the-if-statement/121777/6 "2024-10-30T06:22:41Z")

</div>

Hi,  
Thank you so much. ❤
