COP 3502 Chapter Notes - Chapter 3: Logical Disjunction, Negation, Logical Conjunction
Document Summary
Programs can decide which statements to execute based on a condition. Selection statements-statements that let you choose actions with alternative courses. Boolean expression-an expression that evaluates a boolean value (i. e. true, false) The boolean data type declares a variable with the value either true or false. Java provides 6 relational operators (comparison operators) which can be used to compare 2 values. Example (x=5) x<0 x<=0 x>0 x>=0 x==0 x!=0. Boolean variable-variable that holds a boolean value (e. g. boolean variable=true;) A construct that enables a program to specify alternative paths of execution if(boolean expression) statement(s); If boolean expression evaluates to true, the statement(s) in the block are executed. An if-else statement decides the execution path based on whether the condition is true or false. if(boolean expression) else statement(s) for true; statement(s) for false; An if statement can be inside another if statement to form a nested if statement. if(boolean expression) if(boolean expression) statement(s);