Ch 4 - Gaddis Flashcards
Relational operators
Relational operators allow you to compare numeric and char values and determine whether one is greater than, less than, equal to, or not equal to another.
if statement
The if statement can cause other statements to execute only under certain conditions.
Expanding the if statement
The if statement can conditionally execute a block of statements enclosed in braces.
The if/else statement
The if/else statement will execute one group of statements if the expression is true, or another group of statements if the expression is false.
Nested if statements
To test more than one condition, an if statement can be nested inside another if statement.
The if/else if statement
the if/else if statement tests a series of conditions. It is often simpler to test a series of conditions with the if/else statement than with a set of nested if/else statements.
Flags
A flag is a boolean or integer variable that signals when a condition exists.
Logical operators
Logical operators connect two or more relational expressions into one, or reverse the logic of an expression.
Checking numeric ranges
Logical operators are effective for determining whether a number is in or out of a range.
Menus
You can use nested if/else statements or the if/else if statement to create menu-driven programs. A menu-driven program allows the user to determine the course of action by selecting it from a list of actions.
Validating user input
As long as the user of a program enters bad input, the program will produce bad output. Programs should be written to filter out bad input.
Comparing characters and strings
Relational operators can also be used to compare characters and string objects.
Conditional operator
You can use the conditional operator to create short expressions that work like if/else statements.
Switch statement
The switch statement lets the value of a variable or expression determine where the program will branch.
Blocks and variable scope
The scope of a variable is limited to the block in which it is defined.