Menu

Greater than, less than or less than, greater than?

mkstevo
2021-01-24
2021-01-25
  • mkstevo

    mkstevo - 2021-01-24

    Here's my contribution to daftest question of the week.

    When testing a value to see if it is greater than, or less than a limit I'd write...

    Less than:

    If Value < Limit Then
        Code here...
    End If
    

    For greater than:

    If Value > Limit Then
         Code here...
    End If
    

    If I want to test for a value that is Less than or equal to:

    If Value <= Limit Then
        Code here...
    End If
    

    But should that be:

    If Value =< Limit Then
        Code here...
    End If
    

    Likewise, should I write:

    If Value >= Limit Then
        Code here...
    End If
    

    Or:

    If Value => Limit Then
        Code here...
    End If
    

    Then for something this is not equal to a given value I tend to use:

    If Value <> Limit Then
        Code here...
    End If
    

    Alternatively could I (should I) use:

    If Value != Limit Then
        Code here...
    End If
    

    Or...

    If Value ! Limit Then
        Code here...
    End If
    

    Does any of this matter to GCB or will I end up with the same results?

     
  • Anobium

    Anobium - 2021-01-24

    Great questions....

    "=>" the same as ">=" and is "}"
    "=<" the same as "=<" and is "{"
    "<>" the same as "~"

     
    • Hugh Considine

      Hugh Considine - 2021-01-25

      The single character operators are a bit of a trick used to make part of the compiler slightly simpler. I was very inexperienced when I wrote the code that handles equations, and decided that things could be kept simpler if all operators were a single character. Because ~, { and } have no other meaning to the compiler, those were what I used for <>, <= and >=.
      If that part of the compiler gets a rewrite at any point in the future, the single character versions could disappear, so please use <>, <= and >= (as you would in QBASIC or FreeBASIC).

      (We can probably keep =< though, I don't think that has any other meaning in any other BASIC dialect?)

       
  • mkstevo

    mkstevo - 2021-01-24

    So I can continue with my "preferred"
    ">="
    and
    "=<"
    without issues.

    I don't think I'd enjoy the "{" , "}" versions. I would be forever worried about seeing unmatched opening/closing braces. I'd have to add another nearby and close them...

    The "~" wouldn't offend me in the same way, but it might well confuse me. As I've been happily using "<>" for decades, I think I'll stick with that.

    I woke up this morning, thinking of some code I was going to write, and it had been worrying me in my sleep whether it was "<=" or "=<". Then of course I wondered if I'd been using the wrong one. At least there is no wrong one.

    The relief, phew! I'll hopefully not be waking up in a cold sweat early tomorrow morning.

     
  • mkstevo

    mkstevo - 2021-01-25

    So please use <>, <= and >= (as you would in QBASIC or FreeBASIC).

    Alrighty then. <>, <= and >= it will be from now on.

    Could I request that if the compiler is updated so that "=<" and "=>" stop working, an error is displayed please? Otherwise I'll be deep in the brown stuff...

     
    • Anobium

      Anobium - 2021-01-25

      Well... removing stuff is actually harder than adding stuff.... removing means we could impact/break existing code.

      :-)

       
      • mkstevo

        mkstevo - 2021-01-25

        I should be safe for a while then ;-)

         
  • Jim giordano

    Jim giordano - 2021-01-25

    You didn't say anything about using != instead of <>, is that more inefficient, i.e. does it do a "not" before comparing?

     
  • stan cartwright

    stan cartwright - 2021-01-25

    I have always used, because it was not optional

    <=
    >=
    

    also I always use not port instead of ! port because ! did not mean not in any other basic I learnt.
    edit how is not the same as <> ? I thought it was a bit operation, "not" a comparison of2 vars.

    I found that var-- , ie var=var-1
    compiles same as var--- ,,,,,which it should be
    both work???

     

    Last edit: stan cartwright 2021-01-25

Log in to post a comment.