Results 1 to 3 of 3

Thread: Someone tell me i'm not crazy is this supposed to happen?

  1. #1
    Join Date
    Dec 2016
    Posts
    7
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Default Someone tell me i'm not crazy is this supposed to happen?

    I'm completely new to Simba so i'm not sure if it's a syntax thing but the following evaluates to false

    Writeln(47 >= 40 and 47 < 60);

    why is this false?

    47 is greater than or equal to 40 and 47 is less than 60

  2. #2
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    You need parenthesis around each condition.
    Simba Code:
    writeln((47 >= 40) and (47 < 60));

  3. #3
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by kewlpopo View Post
    I'm completely new to Simba so i'm not sure if it's a syntax thing but the following evaluates to false

    Writeln(47 >= 40 and 47 < 60);

    why is this false?

    47 is greater than or equal to 40 and 47 is less than 60

    47 >= 40 = 1.
    1 and 47 = 0. //Bitwise AND.
    0 < 60 = 1.
    True.

    47 >= 40 = 1.
    1 and 47 = 1. //Logical AND.
    1 < 60 = 1.
    True.

    47 >= 40 = 1.
    47 < 60 = 1.
    1 and 1 = 1. //Both Bitwise & Logical.
    True.

    40 and 47 = 40. //Bitwise AND.
    47 >= 40 = 1.
    1 < 60 = 1.
    True.

    40 and 47 = 40. //Bitwise AND.
    40 < 60 = 1.
    47 >= 1.
    True.

    40 and 47 = 1. //Logical AND.
    47 >= 1 = 1.
    1 < 60 = 1.
    True.


    In Pascal, operator AND takes precedence over comparator operators.

    //First
    47 >= 40 and 47 < 60.
    47 >= 40 < 60.
    47 >= 40 = true || 40 < 60 = true.

    //Last
    47 >= 40 = 1.
    47 < 60 = 1.
    1 and 1 = true.

    Thus the statement holds true even if you do the AND operator first or last.


    Can't see a case in which the above should ever evaluate false.
    Last edited by Brandon; 12-24-2016 at 02:12 AM.
    I am Ggzz..
    Hackintosher

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •