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