microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.26.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

samples/language/ComparisonOperators.qs

89lines · modeblame

ce8303b0Alex Hansen1 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 `>=`.
1d8e82fcScott Carda2 years ago8
ce8303b0Alex Hansen1 years ago9function Main() : Unit {
1d8e82fcScott Carda2 years ago10
ce8303b0Alex Hansen1 years ago11// `==` tests if the first value is equivalent to the second value.
1d8e82fcScott Carda2 years ago12
ce8303b0Alex Hansen1 years ago13// The Boolean value `true`.
14let boolean = 4 == 4;
15Message($"Equality comparison: {boolean}");
1d8e82fcScott Carda2 years ago16
ce8303b0Alex Hansen1 years ago17// The Boolean value `false`.
18let boolean = 4 == 6;
19Message($"Equality comparison: {boolean}");
1d8e82fcScott Carda2 years ago20
ce8303b0Alex Hansen1 years ago21// `!=` tests if the first value is not equivalent to the second value.
22// It is the opposite of `==`.
1d8e82fcScott Carda2 years ago23
ce8303b0Alex Hansen1 years ago24// The Boolean value `false`.
25let boolean = 4 != 4;
26Message($"Inequality comparison: {boolean}");
1d8e82fcScott Carda2 years ago27
ce8303b0Alex Hansen1 years ago28// The Boolean value `true`.
29let boolean = 4 != 6;
30Message($"Inequality comparison: {boolean}");
1d8e82fcScott Carda2 years ago31
ce8303b0Alex Hansen1 years ago32// `<` tests if the first value is strictly less than the second value.
1d8e82fcScott Carda2 years ago33
ce8303b0Alex Hansen1 years ago34// The Boolean value `false`.
35let boolean = 4 < 4;
36Message($"Less than comparison: {boolean}");
1d8e82fcScott Carda2 years ago37
ce8303b0Alex Hansen1 years ago38// The Boolean value `true`.
39let boolean = 4 < 6;
40Message($"Less than comparison: {boolean}");
1d8e82fcScott Carda2 years ago41
ce8303b0Alex Hansen1 years ago42// The Boolean value `false`.
43let boolean = 6 < 4;
44Message($"Less than comparison: {boolean}");
1d8e82fcScott Carda2 years ago45
ce8303b0Alex Hansen1 years ago46// `<=` tests if the first value is less than or equivalent to
47// the second value.
1d8e82fcScott Carda2 years ago48
ce8303b0Alex Hansen1 years ago49// The Boolean value `true`.
50let boolean = 4 <= 4;
51Message($"Less than or equal comparison: {boolean}");
1d8e82fcScott Carda2 years ago52
ce8303b0Alex Hansen1 years ago53// The Boolean value `true`.
54let boolean = 4 <= 6;
55Message($"Less than or equal comparison: {boolean}");
1d8e82fcScott Carda2 years ago56
ce8303b0Alex Hansen1 years ago57// The Boolean value `false`.
58let boolean = 6 <= 4;
59Message($"Less than or equal comparison: {boolean}");
1d8e82fcScott Carda2 years ago60
ce8303b0Alex Hansen1 years ago61// `>` tests if the first value is strictly greater than the second value.
1d8e82fcScott Carda2 years ago62
ce8303b0Alex Hansen1 years ago63// The Boolean value `false`.
64let boolean = 4 > 4;
65Message($"Greater than comparison: {boolean}");
1d8e82fcScott Carda2 years ago66
ce8303b0Alex Hansen1 years ago67// The Boolean value `false`.
68let boolean = 4 > 6;
69Message($"Greater than comparison: {boolean}");
1d8e82fcScott Carda2 years ago70
ce8303b0Alex Hansen1 years ago71// The Boolean value `true`.
72let boolean = 6 > 4;
73Message($"Greater than comparison: {boolean}");
1d8e82fcScott Carda2 years ago74
ce8303b0Alex Hansen1 years ago75// `>=` tests if the first value is greater than or equivalent to
76// the second value.
1d8e82fcScott Carda2 years ago77
ce8303b0Alex Hansen1 years ago78// The Boolean value `true`.
79let boolean = 4 >= 4;
80Message($"Greater than or equal comparison: {boolean}");
1d8e82fcScott Carda2 years ago81
ce8303b0Alex Hansen1 years ago82// The Boolean value `false`.
83let boolean = 4 >= 6;
84Message($"Greater than or equal comparison: {boolean}");
1d8e82fcScott Carda2 years ago85
ce8303b0Alex Hansen1 years ago86// The Boolean value `true`.
87let boolean = 6 >= 4;
88Message($"Greater than or equal comparison: {boolean}");
1d8e82fcScott Carda2 years ago89}