microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
samples/language/ComparisonOperators.qs
89lines · modecode
| 1 | // # Sample |
| 2 | // Comparison Operators |
| 3 | // |
| 4 | // # Description |
| 5 | // Comparison operators in Q# are used to compare one value relative to |
| 6 | // another value of the same type, producing an output Boolean value. |
| 7 | // The comparison operators in Q# are `==`, `!=`, `<`, `<=`, `>`, and `>=`. |
| 8 | |
| 9 | function Main() : Unit { |
| 10 | |
| 11 | // `==` tests if the first value is equivalent to the second value. |
| 12 | |
| 13 | // The Boolean value `true`. |
| 14 | let boolean = 4 == 4; |
| 15 | Message($"Equality comparison: {boolean}"); |
| 16 | |
| 17 | // The Boolean value `false`. |
| 18 | let boolean = 4 == 6; |
| 19 | Message($"Equality comparison: {boolean}"); |
| 20 | |
| 21 | // `!=` tests if the first value is not equivalent to the second value. |
| 22 | // It is the opposite of `==`. |
| 23 | |
| 24 | // The Boolean value `false`. |
| 25 | let boolean = 4 != 4; |
| 26 | Message($"Inequality comparison: {boolean}"); |
| 27 | |
| 28 | // The Boolean value `true`. |
| 29 | let boolean = 4 != 6; |
| 30 | Message($"Inequality comparison: {boolean}"); |
| 31 | |
| 32 | // `<` tests if the first value is strictly less than the second value. |
| 33 | |
| 34 | // The Boolean value `false`. |
| 35 | let boolean = 4 < 4; |
| 36 | Message($"Less than comparison: {boolean}"); |
| 37 | |
| 38 | // The Boolean value `true`. |
| 39 | let boolean = 4 < 6; |
| 40 | Message($"Less than comparison: {boolean}"); |
| 41 | |
| 42 | // The Boolean value `false`. |
| 43 | let boolean = 6 < 4; |
| 44 | Message($"Less than comparison: {boolean}"); |
| 45 | |
| 46 | // `<=` tests if the first value is less than or equivalent to |
| 47 | // the second value. |
| 48 | |
| 49 | // The Boolean value `true`. |
| 50 | let boolean = 4 <= 4; |
| 51 | Message($"Less than or equal comparison: {boolean}"); |
| 52 | |
| 53 | // The Boolean value `true`. |
| 54 | let boolean = 4 <= 6; |
| 55 | Message($"Less than or equal comparison: {boolean}"); |
| 56 | |
| 57 | // The Boolean value `false`. |
| 58 | let boolean = 6 <= 4; |
| 59 | Message($"Less than or equal comparison: {boolean}"); |
| 60 | |
| 61 | // `>` tests if the first value is strictly greater than the second value. |
| 62 | |
| 63 | // The Boolean value `false`. |
| 64 | let boolean = 4 > 4; |
| 65 | Message($"Greater than comparison: {boolean}"); |
| 66 | |
| 67 | // The Boolean value `false`. |
| 68 | let boolean = 4 > 6; |
| 69 | Message($"Greater than comparison: {boolean}"); |
| 70 | |
| 71 | // The Boolean value `true`. |
| 72 | let boolean = 6 > 4; |
| 73 | Message($"Greater than comparison: {boolean}"); |
| 74 | |
| 75 | // `>=` tests if the first value is greater than or equivalent to |
| 76 | // the second value. |
| 77 | |
| 78 | // The Boolean value `true`. |
| 79 | let boolean = 4 >= 4; |
| 80 | Message($"Greater than or equal comparison: {boolean}"); |
| 81 | |
| 82 | // The Boolean value `false`. |
| 83 | let boolean = 4 >= 6; |
| 84 | Message($"Greater than or equal comparison: {boolean}"); |
| 85 | |
| 86 | // The Boolean value `true`. |
| 87 | let boolean = 6 >= 4; |
| 88 | Message($"Greater than or equal comparison: {boolean}"); |
| 89 | } |
| 90 | |