Ch 4 - Statement Forms Flashcards
Control statements fall into two basic classes
Conditionals and iteration
Relational Operators
Are used to compare two values
Can you use relational operators to compare Strings
No
Logical Operators
! Logical Not && Logical And || Logical Or
Short Circuit Evaluation
Style of evaluation which stops as soon as the answer is known
Another name for Boolean variables?
Flags
Test whether done has the value true
if(done)
?: operator (Question-mark colon operator)
condition ? expression 1 : expression 2
Evaluates the condition. If the condition is true expression1 is evaluated. if the condition is falase the value is expression 2.
Example of ?: operator
max = (x > y) ? x : y;
Another example of ?: operator
(nItems == 1 ? “ “ : “s”)
What is the form of the repeat-N-times pattern
for (int i = 0; i < N; i++{
statements etc.
}
Initialization
setting a variable to its proper starting value
Read-until-sentinel pattern
while (true) { PROMPT USER AND READ IN A VALUE if (value == sentintel) break; REST OF BODY }
Sentinel
a special value used to signal the end of the input list
While statement
iterative construct which repeatedly execuates a simple statement or block until the conditional expression is false