Cloudbook: C

  1. Home
  2. Variables
  3. Logicals
  4. § 1 exercise →
Logicals

Logical expressions work with the values true and false, and with operators that return the values true or false.

These expressions are used to modify the flow of statements. For instance, code can do one thing if two different variables have the same value, and something else if they variables do not have the same value. The numbers would be involved in a logical expression that is true if the numbers are even, and that expression is used in a statement that invokes code only on a true expression.

Perl does not have a literal true or false. However, every value is interpreted as either true of false when interpreted in a logical expression. In general, zero is false and everything else is true. For strings, zero means either the empty string or the string '0'. For numbers, zero is zero, simple as that.