BEI - Boolean Expressions and if Statements Overview
Boolean Expressions & if Statements
Introduction
In Java, you can't do very much if your program consists of just a list of commands to be done in order. Your program will not do very much if it cannot choose whether to perform a command or perform the same command more than once. These types of programs are extremely limited! Control structures allow a program to base its behavior on the values of variables.
Key Terms
boolean condition - condition that has two values, true or false
boolean expression - an expression that produces a value of true or false
flow of control - the order in which the individual statements are executed
if statement - a statement that lets a program carry out different actions depending on a condition
relationship operators - operators that compare values
selection statement - a statement that selects among a set of statements depending on the value of the control expression
Module Lessons Preview
In this module, we will study the following topics:
Boolean Expressions: Variables and operators can be combined in an expression that results in a boolean value. In this lesson you will learn some new operators and how they can be used to compute different results.
if Statements & Control Flow: Sometimes in programs it is necessary to skip lines of code if they do not apply to the conditions that are given. What if you want a program to make a decision between multiple results based on different preliminary conditions? In this lesson we will explore how we can modify programs so instead of every line of code being executed, we will only execute the statements that are necessary for each given condition.
If-else Statements: Two-way and multi-way decisions can be written. Here multiple conditions can be executed or skipped. Taking a break from linear programming, if-else statements allow for different outcomes. Conditions allow logical processes to be branched in many directions.
Compound Boolean Expressions: When selecting code to execute, many times there will be multiple conditions. Creating compound boolean expressions allows for more than one condition to be checked before executing code or skipping it to continue to the next statement.
Equivalent Boolean Expressions: The AP Exam includes many boolean logic questions. This lesson shows how to write boolean logic in java. We will explore what laws can be used to create equivalent boolean expressions and how Java compares variables and references to variables.
IMAGES CREATED BY GAVS