Chapter 8 Flashcards
What is a control structure?
A statement ( for, while)+ statements whose execution is controlled
Is it possible for a control structure to have multiple entries?
Yes but only with goto statements
Does goto statements increase or decrease readability?
Decrease
What is a 2 way selection statement?
If then(1st way) else (2nd way)
What is a multiple selector statement
Switch/case statements, elif. Can go to more than 2 places
What is a important design issue with how nested selectors work?
How to know which else is for which if
What is the control expression?
The conditional statement which is usually boolean
How does Java “Assign” a else to an if? (no braces)
It assigns the else to the nearest if.
What is a common way to “Assign” a else to a if?
Forced semantics ( {} )
If the if expression returns a value there must be a ….?
Else clause
What can go inside of a selectable segment in a switch case statement?
Statement sequences or compound statements (blocks)
What components does a counting iterative statement have?
A loop variable + initial value, + terminal value + stepsize
Design issues for counter-controlled loops?
Should loop variable be able to change inside of the loop. What is the scope of the loop variable. What is the loop variable value after the loop
Basic structure for Counter Controlled loops example for C-based languages.
For( expr1; expr2; expr3) statement
Can the 1st expression in a counter controlled loop in c++ declare a variable for use?
Yes. for(int i = 0; i<10; i++)statement
What makes Python for loops “special”?
It has a else clause
What is the use of the else clause in pythons for loop?
It executes after the loop has completed
What is a logically controlled loop?
A Repetition caused by a boolean expression
Can every counter controlled loop be written as a logically-controlled loop?
Yes.
What is pretest vs posttest
Pretest = check condition then execute block
posttest = execute block and then check condition
What are some user loop control mechanisms
Breaks or continues
What does the “continue” control statement do?
Skips the rest of the current iteration
What s iteration based on data structures?
Iteration is controlled by the number of elements in a data structure
What is unconditional branching?
Transfer control to a specific place in program ( uses goto)