/* 6.914, Example 1.4 boolean logic We have another data type like int or float, called 'boolean'. A boolean is just a named piece of information that stores true or false at all times. You declare it and initialize it just like other variables. You can evaluate it in 'if' or 'while' loops, and it will return true or false each time, just like a statement like x>3 would turn true or false depending on the value of x. We can use boolean logic to combine various predicates that evaluate to true or false, like booleans or comparative statements (x>5, x==3, etc.) We can use '&&' (and) to evaluate series of predicates that must all be true, and '||' (or) to evaluate series of predicates that must have at least one true value among them. */ boolean bool1 = true; int x = 5; void setup(){ size(200, 200); } void draw(){ if ((bool1) && (x < 4)){ // since bool1 is true but x is not less than four, this code will not run rect(50, 50, 20, 20); } if ((bool1) || (x < 4)){ // since one predicate (bool1) evaluates to true, it doesn't matter // how the other ones are evaluated: the full statement is evaluated to true rect(50, 100, 20, 20); } if ((bool1) || (x < 4)){ // this is true regardless of the order of the predicates: // even if the first one evaluates to false, one still evaluates to true, // so the whole statement's evaluated as true rect(50, 150, 20, 20); } }