next up previous
Next: Arrays Up: September 20 Previous: Arithmetic


Logic

Logical operators from Java were inherited from C: >, >=, <, <= have highest precedence, then come ==, !=. All have precedence lower than arithmetic operators. Expressions connected with && or || are evaluated from left to right, and evaluation stops as early as it can. An expression is negated with !

if (condition) { statement(s) } tests whether condition is 0 (false) or non-zero (true), and then executes statements(s) if it is true. if (condition) { statement(s) } else { other statement(s) } executes statement(s) if condition is non-zero, and other statement(s) if condition is zero. This resembles Java, once you make the leap from boolean to int conditions.



Danny Heap 2002-12-16