microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.8.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

samples/language/ComparisonOperators.qs

92lines · modeblame

1d8e82fcScott Carda2 years ago1/// # 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 `>=`.
8namespace MyQuantumApp {
9
10@EntryPoint()
efd6847eManvi-Agrawal1 years ago11function Main() : Unit {
1d8e82fcScott Carda2 years ago12
13// `==` tests if the first value is equivalent to the second value.
14
15// The Boolean value `true`.
16let boolean = 4 == 4;
5df46842Joshua Aragon2 years ago17Message($"Equality comparison: {boolean}");
1d8e82fcScott Carda2 years ago18
19// The Boolean value `false`.
20let boolean = 4 == 6;
5df46842Joshua Aragon2 years ago21Message($"Equality comparison: {boolean}");
1d8e82fcScott Carda2 years ago22
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`.
27let boolean = 4 != 4;
5df46842Joshua Aragon2 years ago28Message($"Inequality comparison: {boolean}");
1d8e82fcScott Carda2 years ago29
30// The Boolean value `true`.
31let boolean = 4 != 6;
5df46842Joshua Aragon2 years ago32Message($"Inequality comparison: {boolean}");
1d8e82fcScott Carda2 years ago33
34// `<` tests if the first value is strictly less than the second value.
35
36// The Boolean value `false`.
37let boolean = 4 < 4;
5df46842Joshua Aragon2 years ago38Message($"Less than comparison: {boolean}");
1d8e82fcScott Carda2 years ago39
40// The Boolean value `true`.
41let boolean = 4 < 6;
5df46842Joshua Aragon2 years ago42Message($"Less than comparison: {boolean}");
1d8e82fcScott Carda2 years ago43
44// The Boolean value `false`.
45let boolean = 6 < 4;
5df46842Joshua Aragon2 years ago46Message($"Less than comparison: {boolean}");
1d8e82fcScott Carda2 years ago47
48// `<=` tests if the first value is less than or equivalent to
49// the second value.
50
51// The Boolean value `true`.
52let boolean = 4 <= 4;
5df46842Joshua Aragon2 years ago53Message($"Less than or equal comparison: {boolean}");
1d8e82fcScott Carda2 years ago54
55// The Boolean value `true`.
56let boolean = 4 <= 6;
5df46842Joshua Aragon2 years ago57Message($"Less than or equal comparison: {boolean}");
1d8e82fcScott Carda2 years ago58
59// The Boolean value `false`.
60let boolean = 6 <= 4;
5df46842Joshua Aragon2 years ago61Message($"Less than or equal comparison: {boolean}");
1d8e82fcScott Carda2 years ago62
63// `>` tests if the first value is strictly greater than the second value.
64
65// The Boolean value `false`.
66let boolean = 4 > 4;
5df46842Joshua Aragon2 years ago67Message($"Greater than comparison: {boolean}");
1d8e82fcScott Carda2 years ago68
69// The Boolean value `false`.
70let boolean = 4 > 6;
5df46842Joshua Aragon2 years ago71Message($"Greater than comparison: {boolean}");
1d8e82fcScott Carda2 years ago72
73// The Boolean value `true`.
74let boolean = 6 > 4;
5df46842Joshua Aragon2 years ago75Message($"Greater than comparison: {boolean}");
1d8e82fcScott Carda2 years ago76
77// `>=` tests if the first value is greater than or equivalent to
78// the second value.
79
80// The Boolean value `true`.
81let boolean = 4 >= 4;
5df46842Joshua Aragon2 years ago82Message($"Greater than or equal comparison: {boolean}");
1d8e82fcScott Carda2 years ago83
84// The Boolean value `false`.
85let boolean = 4 >= 6;
5df46842Joshua Aragon2 years ago86Message($"Greater than or equal comparison: {boolean}");
1d8e82fcScott Carda2 years ago87
88// The Boolean value `true`.
89let boolean = 6 >= 4;
5df46842Joshua Aragon2 years ago90Message($"Greater than or equal comparison: {boolean}");
1d8e82fcScott Carda2 years ago91}
92}