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