Reviews Flashcards
(40 cards)
describe the difference between the if/else if statement and a series of if statements
in an if/else if statement, the conditions are tested until one is found to be true. The conditionally executed statements are executed and the program exits if the if/else if statement. In a series of if statements, all of the if statements execute and test their conditions because they are not connected.
in an if/else if statement what is the purpose of a trailing else
the trailing else provides code that is executed when none of the conditions in the if/else if statements are true
what is a flag and how does it work
a flag is a boolean variable signaling that some conditions exists in the program. When the flag is set to false it indicates the condition does not yet exist. When flag is set to true, it indicated that the condition does exist.
can an if statement test expressions other than relational expressions? explain
Yes. The if statement can test any value that yields a boolean value (true or false) or a numeric value. When testing a numeric expression, a nonzero numeric value is considered true, and the the value 0 is considered false.
briefly describe how the && operator works
it takes two expressions as operands and creates a single expression that is true only when both subexpressions are true
briefly descrive how the || operator works
it takes two expressions as operands and creates a single expression that is true when either of the subepressions are true.
why are the relational operaters called relational
because they test for specific relationships between items. The relationships are greater than, less than, equal to, etc.
why do most programmers indent the conditionally executed statements in a decision structure?
it visually sets the conditionally-executed statements apart from the surrounding code. This is so you can easily identify the code that is conditionally-executed.
An expression using the greater than, less than, greater than, or not equal to operator is called a(n) _____ expression.
relational
a relational expression is either ___ or ___
true, false
the value of a relational expression is 0 if the expression is ___ or 1 if the expression is _____.
false, true
the if statement regards an expressison with the value 0 as ___.
false
the if statement regards an expression with a nonzero value as ___.
true
for an if statement to conditionally execute a group of statements, the statements must enclosed in a set of ___.
braces
in an if/else statement, the if part executes its statement or block if the expression is ___, and the else part executes its statement or block if the expression is ___.
true, false
the trailing else in an if/else statement has a similar purpose as the ___ section of a switch statement.
default
the if/else if statement is actually a form of the ___ if statement
nested
If the sub-expression on the left of the __logical operator is false the right sub-expression is not checked
&&
If the sub-expression on the left of the ___ logical operator is true, the right sub-expression is not checked.
||
The ___ logical operator has higher precedence than the other logical operators
!
the logical operators have ___ associativity
left-to-right
the __ logical operators works best when testing a number to determine if it is within range
&&
the ___ logical operator works best when testing a number to determine if it is out of range
||
A variable with ___ scope is only visible when the program is executing in the block containing the variable’s definition
block