Template:RelationalOperationsPlugin: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 7: Line 7:
  │ '''Operation'''  │                '''Description'''                │ '''Example usage'''  │
  │ '''Operation'''  │                '''Description'''                │ '''Example usage'''  │
  ├────────────┼───────────────────────────────────────────┼────────────────┤
  ├────────────┼───────────────────────────────────────────┼────────────────┤
  │  A [[Equal|=]] B    │ Tests if A is '''equal''' to B.                │ [[IF]] A = B [[THEN]]  │
  │  A [[Equal|=]] B    │ Tests if A is '''equal''' to B.                │ [[IF]] A [[Equal|=]] B [[THEN]]  │
  ├────────────┼───────────────────────────────────────────┼────────────────┤
  ├────────────┼───────────────────────────────────────────┼────────────────┤
  │  A [[Not Equal|<>]] B  │ Tests if A is '''not equal''' to B.            │ [[IF]] A <> B [[THEN]] │
  │  A [[Not Equal|<>]] B  │ Tests if A is '''not equal''' to B.            │ [[IF]] A [[Not Equal|<>]] B [[THEN]] │
  ├────────────┼───────────────────────────────────────────┼────────────────┤
  ├────────────┼───────────────────────────────────────────┼────────────────┤
  │  A [[Less Than|<]] B    │ Tests if A is '''less than''' B.                │ [[IF]] A < B [[THEN]]  │
  │  A [[Less Than|<]] B    │ Tests if A is '''less than''' B.                │ [[IF]] A [[Less Than|<]] B [[THEN]]  │
  ├────────────┼───────────────────────────────────────────┼────────────────┤
  ├────────────┼───────────────────────────────────────────┼────────────────┤
  │  A [[Greater Than|>]] B    │ Tests if A is '''greater than''' B.            │ [[IF]] A > B [[THEN]]  │
  │  A [[Greater Than|>]] B    │ Tests if A is '''greater than''' B.            │ [[IF]] A [[Greater Than|>]] B [[THEN]]  │
  ├────────────┼───────────────────────────────────────────┼────────────────┤
  ├────────────┼───────────────────────────────────────────┼────────────────┤
  │  A [[Less Than Or Equal|<=]] B  │ Tests if A is '''less than or equal''' to B.    │ [[IF]] A <= B [[THEN]] │
  │  A [[Less Than Or Equal|<=]] B  │ Tests if A is '''less than or equal''' to B.    │ [[IF]] A [[Less Than Or Equal|<=]] B [[THEN]] │
  ├────────────┼───────────────────────────────────────────┼────────────────┤
  ├────────────┼───────────────────────────────────────────┼────────────────┤
  │  A [[Greater Than Or Equal|>=]] B  │ Tests if A is '''greater than or equal''' to B. │ [[IF]] A >= B [[THEN]] │
  │  A [[Greater Than Or Equal|>=]] B  │ Tests if A is '''greater than or equal''' to B. │ [[IF]] A [[Greater Than Or Equal|>=]] B [[THEN]] │
  └────────────┴───────────────────────────────────────────┴────────────────┘
  └────────────┴───────────────────────────────────────────┴────────────────┘
   The operation should be very obvious for numerical values. For strings,
   The operation should be very obvious for numerical values. For strings,
  the equal/not equal check is also pretty much straight forward, but for the
  the '''equal'''/'''not equal''' check is also pretty much straight forward, but for the
   less/greater checks the [[ASCII]] value of the first different character is
   '''less'''/'''greater''' checks the [[ASCII]] value of the first different character is
                           used for the decision:
                           used for the decision:


  e.g. "abc" is less than "abd", because in the first difference (3rd char)
  e.g. "abc" is '''less than''' "abd", because in the first difference (3rd char)
       the "c" has a lower [[ASCII]] value than the "d".
       the "c" has a lower [[ASCII]] value than the "d".


   This behavior may give you some subtle results, if you are not aware of
   This behavior may give you some subtle results, if you are not aware of
                   the [[ASCII]] values and the written case:
                   the [[ASCII]] values and the written case:
                 
 
  e.g. "abc" is greater than "abD", because small letters have higher [[ASCII]]
  e.g. "abc" is '''greater than''' "abD", because small letters have higher [[ASCII]]
       values than capital letters, hence "c" > "D". You may use either the
       values than capital letters, hence "c" > "D". You may use either the
       [[LCASE$]] or [[UCASE$]] function to make sure both strings use the same case.
       [[LCASE$]] or [[UCASE$]] function to make sure both strings use the same case.
{{FixedEnd}}
{{FixedEnd}}

Revision as of 21:18, 27 November 2022

    In this table, A and B are the values to compare. Both must be of the
      same general type, i.e. either numerical values or STRING values.
 ┌─────────────────────────────────────────────────────────────────────────┐
 │                          Relational Operations                          │
 ├────────────┬───────────────────────────────────────────┬────────────────┤
 │ OperationDescriptionExample usage  │
 ├────────────┼───────────────────────────────────────────┼────────────────┤
 │   A = B    │ Tests if A is equal to B.                 │ IF A = B THEN  │
 ├────────────┼───────────────────────────────────────────┼────────────────┤
 │   A <> B   │ Tests if A is not equal to B.             │ IF A <> B THEN │
 ├────────────┼───────────────────────────────────────────┼────────────────┤
 │   A < B    │ Tests if A is less than B.                │ IF A < B THEN  │
 ├────────────┼───────────────────────────────────────────┼────────────────┤
 │   A > B    │ Tests if A is greater than B.             │ IF A > B THEN  │
 ├────────────┼───────────────────────────────────────────┼────────────────┤
 │   A <= B   │ Tests if A is less than or equal to B.    │ IF A <= B THEN │
 ├────────────┼───────────────────────────────────────────┼────────────────┤
 │   A >= B   │ Tests if A is greater than or equal to B. │ IF A >= B THEN │
 └────────────┴───────────────────────────────────────────┴────────────────┘
   The operation should be very obvious for numerical values. For strings,
 the equal/not equal check is also pretty much straight forward, but for the
   less/greater checks the ASCII value of the first different character is
                           used for the decision:

 e.g. "abc" is less than "abd", because in the first difference (3rd char)
      the "c" has a lower ASCII value than the "d".

   This behavior may give you some subtle results, if you are not aware of
                   the ASCII values and the written case:

 e.g. "abc" is greater than "abD", because small letters have higher ASCII
      values than capital letters, hence "c" > "D". You may use either the
      LCASE$ or UCASE$ function to make sure both strings use the same case.