microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
samples/language/ComparisonOperators.qs
92lines · modeblame
1d8e82fcScott Carda2 years ago | 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 | namespace MyQuantumApp { | |
| 9 | | |
| 10 | @EntryPoint() | |
efd6847eManvi-Agrawal1 years ago | 11 | function Main() : Unit { |
1d8e82fcScott Carda2 years ago | 12 | |
| 13 | // `==` tests if the first value is equivalent to the second value. | |
| 14 | | |
| 15 | // The Boolean value `true`. | |
| 16 | let boolean = 4 == 4; | |
5df46842Joshua Aragon2 years ago | 17 | Message($"Equality comparison: {boolean}"); |
1d8e82fcScott Carda2 years ago | 18 | |
| 19 | // The Boolean value `false`. | |
| 20 | let boolean = 4 == 6; | |
5df46842Joshua Aragon2 years ago | 21 | Message($"Equality comparison: {boolean}"); |
1d8e82fcScott Carda2 years ago | 22 | |
| 23 | // `!=` tests if the first value is not equivalent to the second value. | |
| 24 | // It is the opposite of `==`. | |
| 25 | | |
| 26 | // The Boolean value `false`. | |
| 27 | let boolean = 4 != 4; | |
5df46842Joshua Aragon2 years ago | 28 | Message($"Inequality comparison: {boolean}"); |
1d8e82fcScott Carda2 years ago | 29 | |
| 30 | // The Boolean value `true`. | |
| 31 | let boolean = 4 != 6; | |
5df46842Joshua Aragon2 years ago | 32 | Message($"Inequality comparison: {boolean}"); |
1d8e82fcScott Carda2 years ago | 33 | |
| 34 | // `<` tests if the first value is strictly less than the second value. | |
| 35 | | |
| 36 | // The Boolean value `false`. | |
| 37 | let boolean = 4 < 4; | |
5df46842Joshua Aragon2 years ago | 38 | Message($"Less than comparison: {boolean}"); |
1d8e82fcScott Carda2 years ago | 39 | |
| 40 | // The Boolean value `true`. | |
| 41 | let boolean = 4 < 6; | |
5df46842Joshua Aragon2 years ago | 42 | Message($"Less than comparison: {boolean}"); |
1d8e82fcScott Carda2 years ago | 43 | |
| 44 | // The Boolean value `false`. | |
| 45 | let boolean = 6 < 4; | |
5df46842Joshua Aragon2 years ago | 46 | Message($"Less than comparison: {boolean}"); |
1d8e82fcScott Carda2 years ago | 47 | |
| 48 | // `<=` tests if the first value is less than or equivalent to | |
| 49 | // the second value. | |
| 50 | | |
| 51 | // The Boolean value `true`. | |
| 52 | let boolean = 4 <= 4; | |
5df46842Joshua Aragon2 years ago | 53 | Message($"Less than or equal comparison: {boolean}"); |
1d8e82fcScott Carda2 years ago | 54 | |
| 55 | // The Boolean value `true`. | |
| 56 | let boolean = 4 <= 6; | |
5df46842Joshua Aragon2 years ago | 57 | Message($"Less than or equal comparison: {boolean}"); |
1d8e82fcScott Carda2 years ago | 58 | |
| 59 | // The Boolean value `false`. | |
| 60 | let boolean = 6 <= 4; | |
5df46842Joshua Aragon2 years ago | 61 | Message($"Less than or equal comparison: {boolean}"); |
1d8e82fcScott Carda2 years ago | 62 | |
| 63 | // `>` tests if the first value is strictly greater than the second value. | |
| 64 | | |
| 65 | // The Boolean value `false`. | |
| 66 | let boolean = 4 > 4; | |
5df46842Joshua Aragon2 years ago | 67 | Message($"Greater than comparison: {boolean}"); |
1d8e82fcScott Carda2 years ago | 68 | |
| 69 | // The Boolean value `false`. | |
| 70 | let boolean = 4 > 6; | |
5df46842Joshua Aragon2 years ago | 71 | Message($"Greater than comparison: {boolean}"); |
1d8e82fcScott Carda2 years ago | 72 | |
| 73 | // The Boolean value `true`. | |
| 74 | let boolean = 6 > 4; | |
5df46842Joshua Aragon2 years ago | 75 | Message($"Greater than comparison: {boolean}"); |
1d8e82fcScott Carda2 years ago | 76 | |
| 77 | // `>=` tests if the first value is greater than or equivalent to | |
| 78 | // the second value. | |
| 79 | | |
| 80 | // The Boolean value `true`. | |
| 81 | let boolean = 4 >= 4; | |
5df46842Joshua Aragon2 years ago | 82 | Message($"Greater than or equal comparison: {boolean}"); |
1d8e82fcScott Carda2 years ago | 83 | |
| 84 | // The Boolean value `false`. | |
| 85 | let boolean = 4 >= 6; | |
5df46842Joshua Aragon2 years ago | 86 | Message($"Greater than or equal comparison: {boolean}"); |
1d8e82fcScott Carda2 years ago | 87 | |
| 88 | // The Boolean value `true`. | |
| 89 | let boolean = 6 >= 4; | |
5df46842Joshua Aragon2 years ago | 90 | Message($"Greater than or equal comparison: {boolean}"); |
1d8e82fcScott Carda2 years ago | 91 | } |
| 92 | } |