# Why false || true is not the same as 0 || 1

**URL:** <https://forum.crystal-lang.org/t/why-false-true-is-not-the-same-as-0-1/6375>\
**Category:** Help & Support\
**Created:** [January 27, 2024, 2:42pm UTC](https://forum.crystal-lang.org/t/why-false-true-is-not-the-same-as-0-1/6375 "2024-01-27T14:42:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aboulafia](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@aboulafia](https://forum.crystal-lang.org/u/aboulafia)\
**Post date:** [January 27, 2024, 2:42pm UTC](https://forum.crystal-lang.org/t/why-false-true-is-not-the-same-as-0-1/6375/1 "2024-01-27T14:42:55Z")

</div>

Hi people, when writing tests I stumbled upon this case

[https://play.crystal-lang.org/#/r/ges0](https://play.crystal-lang.org/#/r/ges0)

Line 3 outputs true which is ok  
But line 4 outpus 0 and I would expect 1

I certainly can understand a short circuit for && but not for ||

What do I miss here ?

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [January 27, 2024, 2:56pm UTC](https://forum.crystal-lang.org/t/why-false-true-is-not-the-same-as-0-1/6375/2 "2024-01-27T14:56:07Z")

</div>

You miss that `0` is not falsey like other languages. See [Truthy and falsey values - Crystal](https://crystal-lang.org/reference/1.11/syntax_and_semantics/truthy_and_falsey_values.html).

---

<div class="post-metadata">

**Author:** ![aboulafia](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@aboulafia](https://forum.crystal-lang.org/u/aboulafia)\
**Post date:** [January 27, 2024, 3:01pm UTC](https://forum.crystal-lang.org/t/why-false-true-is-not-the-same-as-0-1/6375/3 "2024-01-27T15:01:00Z")

</div>

That’s big surprise ;-)

Mmm it’s causing some problems, I need to find a solution…

---

<div class="post-metadata">

**Author:** ![aboulafia](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@aboulafia](https://forum.crystal-lang.org/u/aboulafia)\
**Post date:** [January 27, 2024, 3:08pm UTC](https://forum.crystal-lang.org/t/why-false-true-is-not-the-same-as-0-1/6375/4 "2024-01-27T15:08:42Z")

</div>

This C code behaves like I want, output is 1

```auto
#include <stdio.h>

int main() {
  int a = 0;
  int b = 3;
  int r;

  r = a || b;
  printf("%d", r);
}

```

How one can mimic this behaviour in Crystal, given that a and b can be any integer values ?  
How to write this the line `r = a || b;` without casting a and b to some Bool

Edit : Answering myself, of course a cast is needed like in

```auto
when TypeOperator::AND
          r = (l_lit != 0) && (r_lit != 0)
when TypeOperator::OR
          r = (l_lit != 0) || (r_lit != 0)

```

---

<div class="post-metadata">

**Author:** ![tsornson](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/tsornson/32/1651_2.png) [@tsornson](https://forum.crystal-lang.org/u/tsornson)\
**Post date:** [January 27, 2024, 4:43pm UTC](https://forum.crystal-lang.org/t/why-false-true-is-not-the-same-as-0-1/6375/5 "2024-01-27T16:43:01Z")

</div>

A possibly more readable version could be:

```auto
r = !a.zero? || !b.zero?

```

Or even:

```auto
r = !(a.zero? && b.zero?)

```

Otherwise, as you’re edit indicates, you’ll need to convert the numbers to bools if you want to treat them like bools.
