This book presents fundamental theoretical results for designing object-oriented programming languages for controlling swarms. It studies the logics of swarm behaviours. According to behaviourism, all behaviours can be controlled or even managed by stimuli in the environment: attractants (motivational reinforcement) and repellents (motivational punishment). At the same time, there are two main stages in reactions to stimuli: sensing (perceiving signals) and motoring (appropriate direct reactions to signals). This book examines the strict limits of behaviourism from the point of view of symbolic logic and algebraic mathematics: how far can animal behaviours be controlled by the topology of stimuli? On the one hand, we can try to design reversible logic gates in which the number of inputs is the same as the number of outputs. In this case, the behaviouristic stimuli are inputs in swarm computing and appropriate reactions at the motoring stage are its outputs. On the other hand,the problem is that even at the sensing stage each unicellular organism can be regarded as a logic gate in which the number of outputs (means of perceiving signals) greatly exceeds the number of inputs (signals).