Product SiteDocumentation Site

11.3.8. Conditional Execution

Conditional execution tells the SuperCollider interpreter to execute code on the condition that something is true. SuperCollider offers three conditional execution structures, "if", "switch", and "case" statements. Each of these structures is controlled by one or a series of "boolean expressions" (sometimes called "conditional expressions"), which are composed of "boolean operators".

11.3.8.1. Boolean Operators

Boolean operators evaluate to true or false, and are most useful in boolean expressions, where they help to determine which portion of a program to execute.
The following table lists binary boolean operators that take two arguments: one on the left and one on the right. These operators produce either true or false.

Table 11.1. Binary Boolean Operators in SuperCollider

OperatorMeaning
<less than
<=less than or equal to
>greater than
>=greater than or equal to
==equivalent
!=not equivalent
===identical (the same object)
!==not identical (not the same object)
&&logical And
||logical Or
The following table lists unary boolean operators that take one arguments. These operators produce either true or false.

Table 11.2. Unary Boolean Operators in SuperCollider

OperatorMeaning
isPositivetrue if the argument is greater than or equal to 0
isStrictlyPositivetrue if the argument is greater than 0
isNegativetrue if isPositive is false
Unary operators are actually functions, and must be used as such.
(
	var x = 5;
	x.isPositive; // returns "true"
	isNegative( x ); // returns "false"
)
The use of these operators is explained below in the "Boolean Expressions" section.