8.2. Logical Operators

Logical operators are used along with control flow statements to branch the execution of the program logic based on whether a condition is true or false. The &&, ||, and ! operators perform a logical AND, a logical OR, and a logical negation operation, respectively, on their operands. The && and || operators are binary operators and require two operands, which can be any two expressions that evaluate to true or false boolean values. The ! operator is the negation operator, and it negates the expression it is attached to. The true and false operators can be used for checking whether a particular condition is true or false. To simulate an infinite while loop, you can use the true operator:

while (true);

Listing 8.2 shows ...

Get .NET for Java Developers: Migrating to C# now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.