Chapter 3. Expressions

This chapter offers an overview of the expressions defined in Q#. An expression is an entity that the compiler can evaluate to determine its value. Expressions are constructed from literals, variables, operations, and functions using a variety of operators, modifiers, and combinators.

In this chapter, I’ll go over each type of operator, modifier, and combinator that Q# offers. Most Q# operators are very similar to those found in other languages, so I will briefly cover the syntax of the more familiar operators and spend more time on the modifiers and combinators that are less common or are unique to Q#.

I’ll start with the comparative operators and operators acting on the simpler data types, such as Bool and Int, and then follow with the expressions involving more complicated data types, data structures, and finally, operations and functions.


Q# expressions that include multiple operators are evaluated following the rules of operator precedence and associativity, which define the order in which operators are applied. These rules are rather intuitive and similar to those you’d see in other programming languages, so I will not describe them explicitly in this chapter. For a formal definition of the precedence and associativity of all Q# operators and modifiers, see the Q# documentation.

Equality Operators

Equality operators check whether their operands are equal or not. They include equality == and inequality != operators. These operators are defined ...

Get Q# Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.