microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
samples/language/Bool.qs
33lines · modecode
| 1 | /// # Sample |
| 2 | /// Bool |
| 3 | /// |
| 4 | /// # Description |
| 5 | /// The `Bool` type represents Boolean values. Possible values are `true` |
| 6 | /// or `false`. |
| 7 | namespace MyQuantumApp { |
| 8 | |
| 9 | @EntryPoint() |
| 10 | operation Main() : Bool { |
| 11 | // `Bool`s can be operated upon with boolean operators: |
| 12 | let andOp = true and true; |
| 13 | Message($"AND operation: {andOp}"); |
| 14 | |
| 15 | let orOp = false or true; |
| 16 | Message($"OR operation: {orOp}"); |
| 17 | |
| 18 | // Comparisons return booleans: |
| 19 | let eqComparison = 1 == 2; |
| 20 | Message($"Equality comparison: {eqComparison}"); |
| 21 | |
| 22 | // `if` expressions use boolean expressions as their conditions: |
| 23 | if (2 == 2) { |
| 24 | Message("2 equals 2"); |
| 25 | // do something |
| 26 | } else { |
| 27 | Message("2 does not equal 2"); |
| 28 | // do something else |
| 29 | } |
| 30 | |
| 31 | return true; |
| 32 | } |
| 33 | } |